c++ - How to get output from other command line interface programs? -


OK I did some research and I could not change anything useful. I am trying to write a program that will receive input from iwconfig (on linux machine). It will then sort through the input, sorting some calculation and output into a database, sorting through input and output is not an issue (either I really hope that it does not happen) but I'm going to use another command line I am reading input from the program, I am struggling with it. I now have a base Hello World program:

  #include & lt; Iostream & gt; # Include & lt; Cstdlib & gt; using namespace std; Int main () {int numbr = 0; Cout & lt; & Lt; "Hello world!" & Lt; & Lt; Endl; Cin & gt; & Gt; Numbr; Cout & lt; & Lt; "Number is" & lt; & Lt; Numbr; Cout & lt; & Lt; System ("iwconfig"); Return 0; }  

While running the program, it's all Hello World production, ask for my random input and output it again. This output does not output the IWconfig (I run without the output statement) bus system ("iwconfig") as the line runs). Will someone explain how I can run programs such as iwconfig and capture its output?

<

"Will someone explain how I run a program Can iwconfig and capture it as output? "

Check the documentation. It certainly does not provide the price to return, you want to output with your cout statement.

You probably want to establish a pipe between your main and iwconfig program, such as, to control the input and output stream used by the hair process.

Repeated answer has been repeated:

  int main () {int fd_p2c [2], fd_c2p [2], bytes_prod; Pid_t childpid; Four Reidbuffers [80]; String program_name = "iwconfig"; String receive_output = ""; If (pipe (fd_p2c)! = 0 || pipe (fd_c2p)! = 0) {cerr & lt; & Lt; "Failed in pipe \ n"; Exit (1); } Childpid = fork (); If (infant & lt; 0) {cout & lt; & Lt; "Fork Fails" & lt; & Lt; Endl; Exit (-1); } Else if (childpid == 0) {if (dup2 (fd_p2c [0], 0)! = 0 || close (fd_p2c [0])! = 0 || close (fd_p2c [1])! = 0) { Serie Lieutenant; & Lt; "Child: Failed to set up standard input \ n"; Exit (1); } If (dup2 (f2) (fd_c2p [1], 1)! = 1 || closed (fd_c2p [1])! = 0 || closed (fd_c2p [0])! = 0) {cerr & lt; & Lt; "Child: failed to set up standard output \ n"; Exit (1); } Execl (program_name.c_str), program_name.c_str (), (four *) 0); Serie Lieutenant; & Lt; "Failed to execute" & lt; & Lt; Program_name & lt; & Lt; Endl; Exit (1); } And {close (fd_p2c [0]); Close (fd_c2p [1]); Cout & lt; & Lt; "Writing the child:  

Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -