linux - Will running a shell script from a c++ program automatically display the output of the shell script to the console? -
I am taking a Linux class and I have never done C ++. My shell script mainly involves everything , But I need to use it from the c ++ program when I run from the command line, my shell script wants to return the results to the console. When I run it from the C ++ program, my program compiles and runs, but I do not get any output. Is this because I have some error in my C ++ program, or should it be because C ++ and shell scripts interact?
I have seen some questions about grabbing the output from the shell script and using it in the C ++ program, but I do not want to do this. Truly all my C ++ programs run shell scripts.
I just need the output of my shell script to show on the console. Can you help If I am using the code I am using, I can post.
C ++:
#include & lt; Iostream & gt; #include & lt; String & gt; # Include & lt; Stdio.h & gt; # Include & lt; Stdlib.h & gt; using namespace std; Int main (int argc, char * argv []) {string arg; Arg = string (argv [1]); If (argc> = 2) {for (int i = 2; i & lt; argc; i ++) {string temp = string (argv [i]); Arg = RGR + "" + temporary; }} String command; Command = "./findName.sh" + Arg; // cout & lt; & Lt; order; System ("order"); Return 0; }
If you want to display output real time, then you use something like that It can:
file * output stream; Four buffers [1024]; Outputstream = popen (command, "r"); If (Outputstream == Faucet) 1 Return; // could not execute the command while (fgets (buffer, size (buffer), output stream) = null) {// to output the line-by-line buffer and it std :: cout & lt; & Lt; Buffer & lt; & Lt; Std :: endl; } Pclose (Outputstream);
Comments
Post a Comment