Call to external programs with parameters

Many PHP applications call to external utility programs with parameters. The PHP function exec() doesn’t work in very most cases in ExeOutput. There is the HEScript command RunAProgram to replace exec():

For example:

procedure procExecProgram;

begin

RunAProgram(“Notepad”,"","",true,"");

end;

In the PHP script, this procedure has to be called by (if in the pre-installed UserMain HEScript):

exo_runhescriptcom(“UserMain.procExecProgram”);

My observations:

  1. Many PHP scripts call programs with parameters. They should be defined in the second field, such as:

RunAProgram(“Notepad”,“C:\Temp\Temp1.txt”,"",true,"");

  1. White spaces and backslashes in the path are no problem. Example for a macro call:

RunAProgram(“C:\Map Maker\MMmacro.exe”,“C:\Temp\Temp1.bat”,"",true,"");

  1. Output piping will not work as parameter (at least not for me), such as:
    RunAProgram(“Tasklist”," > C:\Temp\Temp1.txt","",true,""); or
    RunAProgram(“Tasklist”," 2>NUL","",true,"");

Alternatives are required, such as ‘wmic’ in case of ‘Tasklist’:

RunAProgram(“wmic”," /output:…","",true,"");

  1. The display mode of the invoked external program was always a pain, already in the PHP interpreter mode (I guess, this is a Windows shortcoming). I also did not manage to make it work here (more doc at http://msdn.microsoft.com/en-us/library/windows/desktop/ms633548(v=vs.85).aspx ). Any advice will be appreciated.

(This more documentation than an inquiry. I thought, my findings might be of help for others who face the same challenges as I did.)

I’m trying to do something similar. The following post Calling ipconfig the person was able to redirect the output to a file for reading. He said that using the /C switch is key. I don’t know if that is the answer for this post, but it could help someone.

Also wmic with /output is working for me too. Thanks for this.