Redirecting output of a C program to another C program with a bash script under Linux
|
makes the program to the right read (as STDIN) the STDOUT of the program on the left.
But your program2
does not read STDIN at all. It reads the arguments (which are NOT STDIN).
You should do:
program2 `program1`
Bash evaluates program1 (when it sees the backquotes), and passes it as an arg to program2.
On my keyboard the backtick (`) is to the left of the "1" key, and above my LEFT TAB key.
EDIT:
If the string output of program1
contains spaces and you want the entire string to be interpreted as one argument, quote the string with "" or '':
program2 "`program1`"
Problem redirecting a C program output in bash
Flushing after newlines only works when printing to a terminal, but not necessarily when printing to a file. A quick Google search revealed this page with further information: http://www.pixelbeat.org/programming/stdio_buffering/
See the section titled "Default Buffering modes".
You might have to add some calls to fflush(stdout), after all.
You could also set the buffer size and behavior using setvbuf.
How to call a C program inside bash script and store its return value to a variable?
The return value of a program is store in the $?
variable. So you only need to add each $?
:
for i in $frames;
do
./enc_ber $bytes $snr $modulation $channel $alamouti
encBER=$((encBER + $?))
done
Note that the value is restricted to eight bits, so the maximum value is 255.
If you want to capture an integer greater than 255 or a float for instance, use stderr for all the things you don't want (fprintf(stderr, "Things I don't want\n");
) and stdout to print the return value you want to catch.
Related Topics
How to Use Schell Script to Read Element from a File, Do Some Calculation and Write Back
How to Make Webdriver Testsuite Created in Windows Machine to Run in a Linux Box
Having Linux Persist Memory Changes to Disk
How to Run a Linux Executable from Any Directory in Terminal
How Does Apparmor Handle Linux-Kernel Mount Namespaces
Function to Search of Multiple Patterns Using Grep
Compiling Kernel Error: Stdio.H: No Such File or Directory
Do I Get a Notification from Epoll When a Fd Is Closed
What Is The 'Tr' Command in Windows
Cygwin Xwin Server Randomly Loses Connection
Setting an Acpi Field in Linux
Eclipse-Mars on Linux: Black Background Color in Tooltip's
Why Doesn't ''Var=Value Echo $Var'' Emit Value
Passwd in One Command Isn't Working
Bash - While Read Line from File Print First and Second Column