stdout to a variable?


 
Thread Tools Search this Thread
Top Forums Programming stdout to a variable?
# 1  
Old 12-01-2006
Question stdout to a variable?

Hi, I need to set stdout to go to a String variable, has anyone got any ideas?
# 2  
Old 12-01-2006
I'm not sure I grasp your question. You're trying to read from stdout??
# 3  
Old 12-01-2006
I want to change stdout to instead of displaying on a monitor put it in a variable.
# 4  
Old 12-01-2006
I think you mean this:
Code:
#!/bin/ksh

myDirectory="$(pwd)"

echo "This is my current directory->[${myDirectory}]"

# 5  
Old 12-01-2006
Basically i have a fork and a execl i need to send the output of the execl instead of onto the screen, into a variable. I need to do this as the need to send it over a socket. I have writing the program in C and C++
# 6  
Old 12-01-2006
Instead of execl use popen - it does just what you want.

man popen.
# 7  
Old 12-02-2006
Computer

brilliant. Popen did just what i wanted. thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How do I store stdout in a variable?

These seems ridiculously simple but I can't get it to work. Using korn shell and I want to pass in a flag to tell my echo statements to either write to the screen for debugging or a file if not. So I have something like: if ; then logout=&1 else logout='logfile.out' fi Then... (2 Replies)
Discussion started by: DJR
2 Replies

2. UNIX for Dummies Questions & Answers

STDout

Hi, I have a program set to read in a text file, change certain characters and then print the altered version to the screen but does anyone know how to save the new version as another text file? And, if possible, how to specify the file name, and perhaps location? Thanks! (2 Replies)
Discussion started by: PerlNutt
2 Replies

3. Shell Programming and Scripting

Redirecting stdout to variable while printing it

Hi everybody, I am trying to do the thing you see in the title, and I can't simply do a=$(svn up) echo $a because the program (svn) gives output on lots of lines and in the variable the output is stored on only one line (resulting in a horribly formatted text). Any tips? Thanks,... (2 Replies)
Discussion started by: ocirne94
2 Replies

4. Shell Programming and Scripting

STDOUT in one line

Hi all, I got a file which contains this. aaaaaaaaaaaaaaaaaaaaaaaa test aaaaaaaaaaaaaa test aaaaaaaaaaa test aaaaaaaaaaaaaaaaa test aaaaaaaaaaaaaaaaaaaaa test aaaaaaaaa test aaaaa test and I want all test output in one row, ideally 3 spaces after the longest word. Thanks (4 Replies)
Discussion started by: stinkefisch
4 Replies

5. UNIX for Advanced & Expert Users

How to use gzip on stdout

Does anyone know how I can use gzip to zip a large log file on the fly. My simulation is currently logging a large file that I need for analysis at a later point. However the files are so huge that I may even run out of disk space. The content is mainly text so when compressed the files are... (2 Replies)
Discussion started by: mitch1710
2 Replies

6. UNIX for Dummies Questions & Answers

not able to capture STDOUT

I am using a third party API to get some real time feed. When I run the command it shows the results properly: etd@mhs-apps5009 $ mamalistenc -m lbm -tport mamaqa -S MLALERTS -s KANA wFinancialStatus Type CTRL-C to exit. (null).MLALERTS.KANA Type: INITIAL Status OK wFinancialStatus |... (5 Replies)
Discussion started by: aks__
5 Replies

7. Shell Programming and Scripting

Executing Stdout ???

Hiya all, Simple question - yet no simple answer im afraid ! Is there a way to execute a shell script (child) which returns one line and get the current (parent) shell to execute the stdout from the child ??? example child.sh #!/bin/sh echo "setenv DISPLAY xxx:03" parent_prompt>... (5 Replies)
Discussion started by: fawqati
5 Replies

8. UNIX for Dummies Questions & Answers

logging stdout

Hello I run a program that creates number of processes. Is there a way of viewing their standard output on terminal and logging it to a log file simultaneously? (3 Replies)
Discussion started by: masha
3 Replies

9. Shell Programming and Scripting

ksh - get stdout name as variable

Writing a ksh script. If someone starts a process with: test.ksh > date.log How can I grab 'date.log' name as a variable in test.ksh? I need to get the 'date.log' name (not the contents) as a variable...without entering something like 'test.ksh date.log > date.log' (4 Replies)
Discussion started by: mhcueball2
4 Replies

10. UNIX for Dummies Questions & Answers

pipe and stdout

Hi there I know that this isn't the place to put a question like this i supose, but i'm geting desperated. I have searched in interbase forums and nothing helped. If anyone can help me i would apreciated. I'm using HP-UX with a version 3 of interbase wich means i can't split the backup file into... (3 Replies)
Discussion started by: vascobrito
3 Replies
Login or Register to Ask a Question