cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
dinesh_redhawk
Pilgrim

how to capture the output/errors from command line operations done by LaunchAppWait

Hello Guys,

I am performing some command line operations by launching the CMD using LaunchAppandWait but for certain scenarios or error situations, i need to capture the output/status of the commands executed and also need to capture the errors in case of any failure. How can i achieve this?
currently, we are planning to implement the commandline operations via a C# program and send the return status to Installshield, but i personally want to do this through Installscript or something (if possible).
Please let me know your views and suggestions.
If you have a code snippet that i can refer, then it will be very helpful.

Thanks
Labels (1)
0 Kudos
12 Replies
rguggisberg
Intrepid explorer

Re: how to capture the output/errors from command line operations done by LaunchAppWait

Yes that is possible... I do it in numerous places. I tried to post a sample from one of my projects here but the security policy of this site prevents me from posting that code. Send me a private message and I will send to you. Basically what you want to do is pipe results to a text file and then you can use FileGrep,, etc as needed.
0 Kudos
rguggisberg
Intrepid explorer

Re: how to capture the output/errors from command line operations done by LaunchAppWait

Can't post code in private message either 😞
Here are a couple notes that I can post 🙂

Notes:
1. Don't use LAAW_OPTION_HIDDEN option because if there is a pause in the bat file you will be stuck!
2. In many cases you should verify that the app actually launched like this:
nResult = LaunchAppAndWait ("\"" + szName + "\"", "", LAAW_OPTION_WAIT);
if (nResult < 0) then
MessageBox ("Unable to launch "+ szName + ". Put some message here.",WARNING);
endif;

UPDATE:
Zip file attached.
0 Kudos
dinesh_redhawk
Pilgrim

Re: how to capture the output/errors from command line operations done by LaunchAppWait

rguggisberg wrote:
Yes that is possible... I do it in numerous places. I tried to post a sample from one of my projects here but the security policy of this site prevents me from posting that code. Send me a private message and I will send to you. Basically what you want to do is pipe results to a text file and then you can use FileGrep,, etc as needed.


Thanks again Bro!!! your quick response always helps me. Need one suggestion on your solution. In my case i have to do this action in nearly 100 places, so do you think its advisable to perform the writing of file, reading from it and deleting it in the end, every time. Will it not effect performance and in some scenario may fail due to write permissions (not sure, if we use temp folder). Please advise.
0 Kudos
rguggisberg
Intrepid explorer

Re: how to capture the output/errors from command line operations done by LaunchAppWait

I don't think the performance hit will be significant. I think you will find that InstallShield writes numerous other files to the Temp folder. You could always do another CA very early in the installation process to verify that the user has write access to the temp folder by writing and deleting a temporary file. Post a message if not.
0 Kudos
dinesh_redhawk
Pilgrim

Re: how to capture the output/errors from command line operations done by LaunchAppWait

rguggisberg wrote:
I don't think the performance hit will be significant. I think you will find that InstallShield writes numerous other files to the Temp folder. You could always do another CA very early in the installation process to verify that the user has write access to the temp folder by writing and deleting a temporary file. Post a message if not.


Hello rguggisberg,
Thanks, after referring to your code, i tried using the below code snippet.
On running the code, i noticed that :

in SUCCESS scenarios: The file gets created and it has the output written into it.

in ERROR scenarios: A Blank file gets created.

Could you please help me in identifying the root cause. I want the output to be written in BOTH scenarios.


szTempFile = "ErrorLogTest.txt";
szTempFolderPath = TempFolder ^ szTempFile;

szGroup = "TestGroup";
szComment = "TestGroup";

szCmdLine = "%/C \"NET LOCALGROUP \"" +szGroup +"\" " +"\/comment\:\""+szComment +"\" \/add"+" >" + szTempFolderPath;

//Launch the program with the parameters
if (LaunchAppAndWait(szProgram, szCmdLine, LAAW_OPTION_WAIT|LAAW_OPTION_HIDDEN) < 0) then
MessageBox("Failed to execute the program", INFORMATION);
else
nResult = LAAW_PARAMETERS.nLaunchResult;
szResult = FormatMessage(nResult);

MessageBox("Program Executed:"+szResult, INFORMATION);
endif;


Please help.
Thanks
0 Kudos
rguggisberg
Intrepid explorer

Re: how to capture the output/errors from command line operations done by LaunchAppWait

The reason you are getting the result that you are is because you are piping the STDOUT to the file (with >) but not STDERR. To get the result that I understand you want, change this line:
szCmdLine = "%/C \"NET LOCALGROUP \"" +szGroup +"\" " +"\/comment\:\""+szComment +"\" \/add"+" >" + szTempFolderPath;
to
szCmdLine = "%/C \"NET LOCALGROUP \"" +szGroup +"\" " +"\/comment\:\""+szComment +"\" \/add"+" >" + szTempFolderPath +" 2>&1" ;
That will pipe both STD and STDERR to the file.

A word of caution... I see you are using LAAW_OPTION_HIDDEN. Be aware that if your bat file stops for any reason your install will hang because there will be no window in which the operator can reply. Certainly verify that your bat file has no PAUSE's in it..
0 Kudos
dinesh_redhawk
Pilgrim

Re: how to capture the output/errors from command line operations done by LaunchAppWait

rguggisberg wrote:
The reason you are getting the result that you are is because you are piping the STDOUT to the file (with >) but not STDERR. To get the result that I understand you want, change this line:
szCmdLine = "%/C \"NET LOCALGROUP \"" +szGroup +"\" " +"\/comment\:\""+szComment +"\" \/add"+" >" + szTempFolderPath;
to
szCmdLine = "%/C \"NET LOCALGROUP \"" +szGroup +"\" " +"\/comment\:\""+szComment +"\" \/add"+" >" + szTempFolderPath +" 2>&1" ;
That will pipe both STD and STDERR to the file.

A word of caution... I see you are using LAAW_OPTION_HIDDEN. Be aware that if your bat file stops for any reason your install will hang because there will be no window in which the operator can reply. Certainly verify that your bat file has no PAUSE's in it..


@rguggisberg: Thanks sir, you are a life saver. I will definitely try this and revert. Thank you very much. 🙂
0 Kudos
dinesh_redhawk
Pilgrim

Re: how to capture the output/errors from command line operations done by LaunchAppWait

rguggisberg wrote:
The reason you are getting the result that you are is because you are piping the STDOUT to the file (with >) but not STDERR. To get the result that I understand you want, change this line:
szCmdLine = "%/C \"NET LOCALGROUP \"" +szGroup +"\" " +"\/comment\:\""+szComment +"\" \/add"+" >" + szTempFolderPath;
to
szCmdLine = "%/C \"NET LOCALGROUP \"" +szGroup +"\" " +"\/comment\:\""+szComment +"\" \/add"+" >" + szTempFolderPath +" 2>&1" ;
That will pipe both STD and STDERR to the file.

A word of caution... I see you are using LAAW_OPTION_HIDDEN. Be aware that if your bat file stops for any reason your install will hang because there will be no window in which the operator can reply. Certainly verify that your bat file has no PAUSE's in it..


Hi rguggisberg, I tried your suggested command, it seems to perform the job. BUT iam facing a weird problem-
a) when i try the below mentioned command directly in CMD prompt, it works - file gets created and output gets written.
NET LOCALGROUP "TestGroup" /comment:"TestGroup" /add >C:\Users\H237454\AppData\Local\Temp\ErrorLogTest.txt 2>&1

b) when i use the below code in Installscript and try to run the command from Installer, no file is getting created. BUT TestGroup is getting created, Dont know whats going wrong.
szCmdLine = "%/C \"NET LOCALGROUP \"" +szGroup +"\" " +"\/comment\:\""+szComment +"\" \/add"+" >" + szTempFolderPath +" 2>&1" ;

Can you please run the code snippet that i posted earlier and replace the szCmdLine with whatever you suggested, and revert.
I am not getting what is going wrong with Installscript command. 😞

Please help.
0 Kudos
rguggisberg
Intrepid explorer

Re: how to capture the output/errors from command line operations done by LaunchAppWait

Hi,

Sorry I missed this before... What is the % for in the line below?
szCmdLine = "%/C \"NET LOCALGROUP \"" +szGroup +"\" " +"\/comment\:\""+szComment +"\" \/add"+" >" + szTempFolderPath +" 2>&1" ;

I would remove that for sure. Beyond that... presumably you are executing CMD and passing the above command line. That is not necessary. Try launching NET and pass it a szCmdLine something like this:
szCmdLine = "LOCALGROUP " +szGroup +"\" " +"\/comment\:\""+szComment +"\" \/add"+" >" + szTempFolderPath +" 2>&1" ;
Although there could be other problems. Can you post some of your InstallScript code too?
0 Kudos