Calling a command line program from Zorro and receiving output?

Posted By: Hredot

Calling a command line program from Zorro and receiving output? - 03/12/18 04:05

Can Zorro call a command line program from within a script and receive the program output as a string, or a numeric value?
If yes, how can this be done?
Posted By: jcl

Re: Calling a command line program from Zorro and receiving output? - 03/12/18 12:01

Depends on how the program produces output. The simplest way would be through a file.
Posted By: Hredot

Re: Calling a command line program from Zorro and receiving output? - 03/12/18 13:27

The external program could write to a file, or do a cout to console. There is a C function "popen" in stdio that could receive such a stream, but I'm not sure if stdio is available in Zorro.

Perhaps you could give a short code snippet on how to call a command line command from Zorro as an example?
Posted By: AndrewAMD

Re: Calling a command line program from Zorro and receiving output? - 03/12/18 14:26

You can make a DLL that exports any functions you need, such as _popen and its brethren.

That said, I wouldn't use _popen(). I'd write a DLL that uses Boost Process to launch a child process and Boost Asio to communicate with its stdin & stdout - or perhaps with a pipe.

Or just do the file method. That's the five-minute solution. laugh

EDIT - Honorable mention goes to the Windows API. Some of this stuff is actually included in Zorro's windows.h header.
Posted By: Hredot

Re: Calling a command line program from Zorro and receiving output? - 03/12/18 14:51

Thanks for the suggestions! Yeah, I'm fine with the file method, still curious about the simplest code to execute a command line from Zorro. Is a custom dll the only way?
Posted By: Petra

Re: Calling a command line program from Zorro and receiving output? - 03/12/18 15:00

Code:
exec("C:\\Directory\\Program","",1);

Posted By: Hredot

Re: Calling a command line program from Zorro and receiving output? - 03/12/18 15:18

Thank you Petra, this is perfect!
© 2024 lite-C Forums