This website uses cookies. By clicking Accept, you consent to the use of cookies. Click Here to learn more about how we use cookies.
Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
- Revenera Community
- :
- InstallShield
- :
- InstallShield Forum
- :
- Re: how to capture the output/errors from command line operations done by LaunchAppWait
Subscribe
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Jun 30, 2017
01:15 AM
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
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
(12) Replies
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Jun 30, 2017
08:05 AM
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.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Jun 30, 2017
08:13 AM
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.
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.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Jul 04, 2017
04:26 AM
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.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Jul 05, 2017
08:10 AM
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.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Jul 10, 2017
07:51 AM
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
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Jul 12, 2017
02:36 PM
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..
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..
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Jul 13, 2017
12:00 AM
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. 🙂
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Jul 13, 2017
07:22 AM
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.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Jul 13, 2017
10:51 AM
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?
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?
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Jul 14, 2017
01:06 AM
rguggisberg wrote:
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?
Hi rguggisberg,
"%/C" is required in case you want to execute the command that you have passed and automatically want it to exit later.
For your reference, i have posted here the code snippet. Please try and let me know. The requirement here is to get a file created in temp folder where the output/error will be written.
I am not able to paste the code snippet here...it gives security error. However, i have attached the code to the post in a file. Please check. Thanks for your help.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Jul 14, 2017
05:08 AM
rguggisberg wrote:
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?
Hi rguggisberg,
i got the fix but it has got another small issue 😛 .
I changed the szCmdLine to
szCmdLine = "%/C \"NET LOCALGROUP \"" +szGroup +"\" " +"\/comment\:\""+szComment +"\" \/add \""+" >" + szTempFolderPath+" 2>&1" ;
This resulted the file to get created with the output. BUT BUT BUT, there is another problem now.
The szResult in my code is now returning "The specified path cannot be found". This happens in the case when the group is already present and it writes this message in the log file "The specified local group already exists"
My observation says that because of the double quotes, Installer is thinking the entire command as some kind of file path. You can verify this by printing the szCommand in a MessageBox.
Any suggestions? These small silly issues takes lot of time to debug and fix 😛
Thanks again.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Jul 14, 2017
08:52 AM
Yest, these things take time to fix. I answered in your other post.
Good luck.
Good luck.
![](/skins/images/D60DF682EA37BF37032955CE10F3F0BB/responsive_peak/images/icon_anonymous_message.png)