Community Forums
Page 1 of 2 12 LastLast
Results 1 to 5 of 10

Thread: Unable to Capture results properly from CMD line parameter executions by LaunchApp

  1. #1
    Join Date
    May 2011
    Posts
    37

    Question Unable to Capture results properly from CMD line parameter executions by LaunchApp

    Hello Friends,

    I am facing problem in fetching the return result properly from LaunchAppAndWait where i am trying to execute the CMD command.

    Code:
    function CreateGroup()
    	STRING szGroup,szTempFile, szTempFolderPath;
    	STRING szProgram,szCmdLine, szResult, szComment;
    	NUMBER nResult;
    
    begin
    	szProgram =SystemFolder^"cmd.XXX"; //Need to remove executable format as forum not allowing the post to submit. IGNORE IT!!
    	szTempFile = "ErrorLogTest.txt";
    	szTempFolderPath = TempFolder ^ szTempFile;	
    	szGroup = "TestGroup";
    	szComment = "TestGroup";
    	
    	szCmdLine = "%/C \"NET LOCALGROUP \""+szGroup+"\" "+"\/comment\:\""+szComment+"\" \/add >"+szTempFolderPath+" 2>&1\"";
    	MessageBox(szCmdLine,INFORMATION);
    
    	//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);
    		//if the launched applications returns an error, it will be logged
    		if (nResult != 0) then
    			SprintfMsiLog("The returned error is:\"" + szResult + "\"");
    		else
    			SprintfMsiLog("The returned information is:\"" + szResult + "\"");
    		endif;
    		MessageBox("Program Executed:"+szResult, INFORMATION);
    	endif;	
    end;
    When I execute the code, the ErrorLogTest.txt file is getting created with all the outputs/errors properly. BUT

    The szResult in my code is returning "The specified file path cannot be found" and nResult is -2. Definitely its not correct return status.
    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".

    In case when the group doesnt exist, it creates the group and szResult shows "Operation completed successfully" and the same gets written in the log file too.

    My observation shows that because of the double quotes due to /C, Installer is somehow thinking the entire command as some kind of file path. You can verify this by printing the szCommand in a MessageBox.

    Is there any problem with my code? I want to get correct result in szResult in both error and success cases. How to get it. I know i can get it from the logfile that i am printing but i want to get directly from szResult without having to read the file repeatedly.

    Any help guys...please. Thanks

  2. #2
    Join Date
    May 2007
    Location
    Eden Praire, MN
    Posts
    719
    Hi,

    I just took a look at one of my projects and happen to have similar code. Here is mine for reference. It is a bit different than yours in that I only write to file if command succeeds and I only write to file if output contains what I am looking for.:
    Code:
        szCmdLine = "/C net localgroup administrators | find /I \"" + szAccount + "\" && echo(>" + szTempFileSpec;
    Here is your code. Need to be careful with placement of +.
    Code:
    	szCmdLine = "%/C \"NET LOCALGROUP \""+szGroup+"\" "+"\/comment\:\""+szComment+"\" \/add >"+szTempFolderPath+" 2>&1\"";
    Try this (untested):
    Code:
    	szCmdLine = "/C NET LOCALGROUP + \" + szGroup + "\  \"/comment:\" + szComment + "\ "\/add >\" + szTempFolderPath + \" 2>&1\"";

  3. #3
    Join Date
    May 2011
    Posts
    37
    Quote Originally Posted by rguggisberg View Post
    Hi,

    I just took a look at one of my projects and happen to have similar code. Here is mine for reference. It is a bit different than yours in that I only write to file if command succeeds and I only write to file if output contains what I am looking for.:
    Code:
        szCmdLine = "/C net localgroup administrators | find /I \"" + szAccount + "\" && echo(>" + szTempFileSpec;
    Here is your code. Need to be careful with placement of +.
    Code:
    	szCmdLine = "%/C \"NET LOCALGROUP \""+szGroup+"\" "+"\/comment\:\""+szComment+"\" \/add >"+szTempFolderPath+" 2>&1\"";
    Try this (untested):
    Code:
    	szCmdLine = "/C NET LOCALGROUP + \" + szGroup + "\  \"/comment:\" + szComment + "\ "\/add >\" + szTempFolderPath + \" 2>&1\"";
    Hi,

    Its not working man, whatever you asked me to try. In fact it threw lot of compile errors for improper use of "" or /. I corrected them and then tried to run and it threw error: "Invalid function"
    Any more suggestions?
    Thanks

  4. #4
    Join Date
    May 2007
    Location
    Eden Praire, MN
    Posts
    719
    I will test and post when I get time.

  5. #5
    Join Date
    May 2011
    Posts
    37
    Quote Originally Posted by rguggisberg View Post
    I will test and post when I get time.
    Thanks Bro

Page 1 of 2 12 LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •