'How to pass a C program as a Command Line Argument [duplicate]
Im not sure if it is possible, but would like to know if i can use the result of a main() function as the command line argument for another program. im currently using gcc compiler on linux so i figure it would look something like this:
./listcommandlinearugments ./generaterandomstring
but this does not work... in the above example the first program (listcommandlinearguments) simply lists ./generaterandomstring as a command line arugment instead of using the result of the main funtion (0) because it was int main() and returned 0.
Solution 1:[1]
You can use backticks to insert the output of a program into another command:
./generaterandomstring `./listcommandlinearugments`
EDIT:
Since you want the return value of the listcommandlinearugments, run that first, then use $? to get the return value:
./generaterandomstring
./listcommandlinearugments $?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
