Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Search Forums:



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-13-2010
Registered User
 

Join Date: Mar 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Question Redirecting stdin/stdout to/from command from/to string

Hi,
I am working on a project where I have to generate and execute nasm code on-the-fly. I generate the code in a file program.asm and then execute it.This output is to stdout which i redirect to an output file which i read back to compare results:
system("nasm -f elf program.asm > output");
The problem is I have to do this process (generate code and execute) a lot of times each time i run my program which slows the execution time due to so much file I/O.

Is there some shell trick by which I can generate my code in a string buffer (instead of the file program.asm) and pass it as input to nasm.
Similarly, can I capture the output of nasm into another string buffer without writing it to a file.

Same applies for compiling c programs using gcc. Can my c program be present in a string which i then compile using gcc by redirecting its input from a file to the string. Likewise, can i redirect the output of my c program to a string instead of stdout or any other file before.
Sponsored Links
    #2  
Old 03-14-2010
ɹǝsn *sıɹɐlos*
 

Join Date: Dec 2007
Location: Paris
Posts: 3,712
Thanks: 11
Thanked 296 Times in 276 Posts
Perhaps using a tmpfs based filesystem would improve the performance enough.
Sponsored Links
    #3  
Old 03-14-2010
Registered User
 

Join Date: Mar 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks for the reply but I don't have that option.

Anyways, I found a way to redirect stdout to a string. Its at Get from stdout a string - GIDForums
This method uses pipes. Haven't tried it yet but seems it will work.

Any similar ideas for taking input from a string or some memory buffer instead of files??
    #4  
Old 03-14-2010
ɹǝsn *sıɹɐlos*
 

Join Date: Dec 2007
Location: Paris
Posts: 3,712
Thanks: 11
Thanked 296 Times in 276 Posts
Quote:
Originally Posted by doc_cypher View Post
Thanks for the reply but I don't have that option.
What OS are you running that doesn't support a memory backed filesystem ?
Quote:
Any similar ideas for taking input from a string or some memory buffer instead of files??
The most similar way would be using pipes for input too.
Sponsored Links
    #5  
Old 03-15-2010
Registered User
 

Join Date: Mar 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
What OS are you running that doesn't support a memory backed filesystem ?
Well, sorry but I don't know anything about tmpfs. So I said I don't have that option.
How can I use it ? I am using ubuntu 9.04.

---------- Post updated at 10:56 AM ---------- Previous update was at 10:56 AM ----------
Sponsored Links
    #6  
Old 03-15-2010
ɹǝsn *sıɹɐlos*
 

Join Date: Dec 2007
Location: Paris
Posts: 3,712
Thanks: 11
Thanked 296 Times in 276 Posts
Google first hit: Create turbocharged storage using tmpfs
Sponsored Links
Closed Thread

Tags
on-the-fly, redirect, stdout, string

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
can't close stdin/stdout in shell Corona688 Shell Programming and Scripting 10 02-18-2010 07:52 PM
Redirecting stdin from fd 3-9? niceguyeddie Shell Programming and Scripting 3 09-03-2009 04:13 PM
stdout/stdin + flushing buffers JamesGoh Programming 9 10-02-2008 08:15 PM
C++ How to use pipe() & fork() with stdin and stdout to another program vvaidyan Programming 2 05-16-2008 07:30 PM
Redirecting to stdin flame_eagle Shell Programming and Scripting 4 02-20-2008 03:25 PM



All times are GMT -4. The time now is 03:45 AM.