06-02-2017 10:58 AM
Hello everyone,
I have a program that executes a file, and have used the following code to run the file:
int exec=0;
LaunchExecutableEx ("cmd.exe /c config.exe parameters ", LE_HIDE, &exec);
When the config.exe is ran, it generates output on the command screen which I would like to redirect and store in an array. Is this possible?
I am trying to avoid redirecting the output to a file and storing it from there.
Thanks!
06-03-2017 10:06 AM
Hi!
Could you elaborate on why this is needed? The current methodology I can see working is using pipes, this is discussed in the below linked stackoverflow thread:
Although I believe popen would only redirect the settings when the pipe is closed. To get continual data I would try looking into the first suggestion of passing a STARTUPINFO structure with the handles. There is a microsoft example from first glance:
Hopefully this will help provide a solution,
Ed
06-05-2017 09:52 AM
Hello Ed,
Thanks for the response. I've tried using popen but it doesn't seem to be supported in LabWindows. Whenever I try to compile the program, it doesn't recognize that function. Do you have any idea why?
Thanks!
06-05-2017 10:05 AM
You will need to include the headers for this Windows function which is included in the requirements section for the MSDN page:
06-05-2017 10:52 AM
I've included all the required headers, and still get this message:
20, 17 error: implicit declaration of function '_popen' is invalid in C99. Make sure that you include the function prototype.
Thanks again for all your help I really appreciate it!
06-05-2017 10:57 AM
These issues are C and Win32 based and not explicitly LabWindows/ANSI C, the solution is to declare the function as described in the below thread:
Therefore include just after your header declaration and before main, the line:
FILE *_popen( const char *command, const char *mode );
06-05-2017 11:48 AM
So I tried that, and then I received this error:
error: Undefined symbol '__pclose' referenced in "c:\Users\mjj\Desktop\test\cvibuild.test\Debug\test.obj".
error: Undefined symbol '__popen' referenced in "c:\Users\mj\Desktop\test\cvibuild.test\Debug\test.obj".
Is there a library I have to include?
Thanks again for your help and your fast responses!
06-06-2017 08:31 AM
I was unable to get _popen to work, but ended up finding a code someone had written that performed exactly what I wanted to do, and it works great. Below is the link to that code:
Thanks again for all the help!