![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Assigning output of a command to variable | jeriryan87 | Shell Programming and Scripting | 9 | 06-30-2008 05:55 PM |
| ls command output to variable in script | dsrookie | UNIX for Dummies Questions & Answers | 1 | 03-10-2008 04:14 PM |
| Assigning output of command to a variable | oma04 | Shell Programming and Scripting | 5 | 06-27-2006 01:11 PM |
| redirect command output to variable | hugow | UNIX for Dummies Questions & Answers | 1 | 06-22-2005 07:43 AM |
| Command output to a variable. | videsh77 | Shell Programming and Scripting | 8 | 12-16-2004 06:06 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Command output into a variable
Hi, with this command:
cu -l /dev/ttyACM0 -s 9600 > name.txt I put the output of the port in a txt Is posible to do the same (or similar) in a var directly, inside a C program? cu -l /dev/ttyACM0 -s 9600 > variable ? I have trying this withs pipes, but i dont know how to adress te port to a pipe. Also i have tried with function read, fgets, etc.. but I don't why, it doesn't works, just write. Thank you |
|
||||
|
Hi, thank you very much.
popen seems to works ok. But there s a problem with pclose(); when I write: file = popen ("cu -l /dev/ttyACM0 -s 9600", "w"); //WRITE fputs("AT\n",file); pclose(file) this run ok. In console: Connected. cu: End of file on terminal Disconnected. But with: file = popen ("cu -l /dev/ttyACM0 -s 9600", "r"); //READ there is no response when I try to close the pipe. Not Disconnected, and so i can't write one more time. I'm trying to do this, because I need a bidirectional pipe , and the only way I know to do this is to: open to write -- > close --> open to read ---> close and another time the same BUt pclose function failed in read mode . thank you |
|
||||
|
popen is unidirectional, closing and reopening will not allow you to establish any decent communication.
Ever heard of named pipes? Create a named pipe /tmp/cu.in, use it: file = popen ("cu -l /dev/ttyACM0 -s 9600 < /tmp/cu.in", "r"); //READ Then you could write to /tmp/cu.in what you want as input for cu, and retrieve the results with fgets. But you really should be using some kind of inter-process communication, messaging. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|