Jump to content

Can't find correct usage for IF EXISTS


Recommended Posts

Hi,

 

I has been using WPIW for quite a while.

Moving from XP to Seven, I bump into a syntax problem I suppose.

 

I used a cmds[pn] statement as follow

 

 

 

cmds[pn]=[' "%wpipath%\\PathToExe\\MainExe.exe" /s /v/qn','{CMD} IF EXIST "%wpipath%\\PathToExe\\ExeFile.exe" start "Title" /WAIT   "%wpipath%\\PathToExe\\ExeFile.exe" /s /v/qn ']; cond[pn]=['FileExists("%wpipath%\\PathToExe\\MainExe.exe")'];

 

I always get and error 

 

 

cmd2 *** Fail *** (returned code 999): IF EXIST "D:\WPI\PathToExe\ExeFile.exe" start "Title" /WAIT "D:\WPI\PathToExe\ExeFile.exe" /s /v/qn

 

What is really weird, it is working under XP (tested with version 8.5)

but not with version 8.6.3

 

 

Can anyone give some advices/hints to debug it ?

 

Regards.

 

Giles 

Edited by gillesg
Link to comment
Share on other sites

Edit:  Just noticed, you need to drop the "S" on your "EXISTS" part.  See below for the other part of my post.

-----------------------

Try using the command "if /?", you get the following:

C:\>if /?Performs conditional processing in batch programs.IF [NOT] ERRORLEVEL number commandIF [NOT] string1==string2 commandIF [NOT] EXIST filename command  NOT               Specifies that Windows should carry out                    the command only if the condition is false.  ERRORLEVEL number Specifies a true condition if the last program run                    returned an exit code equal to or greater than the number                    specified.  string1==string2  Specifies a true condition if the specified text strings                    match.  EXIST filename    Specifies a true condition if the specified filename                    exists.  command           Specifies the command to carry out if the condition is                    met.  Command can be followed by ELSE command which                    will execute the command after the ELSE keyword if the                    specified condition is FALSEThe ELSE clause must occur on the same line as the command after the IF.  Forexample:    IF EXIST filename. (        del filename.    ) ELSE (        echo filename. missing.    )The following would NOT work because the del command needs to be terminatedby a newline:    IF EXIST filename. del filename. ELSE echo filename. missingNor would the following work, since the ELSE command must be on the same lineas the end of the IF command:    IF EXIST filename. del filename.    ELSE echo filename. missingThe following would work if you want it all on one line:    IF EXIST filename. (del filename.) ELSE echo filename. missingIf Command Extensions are enabled IF changes as follows:    IF [/I] string1 compare-op string2 command    IF CMDEXTVERSION number command    IF DEFINED variable commandwhere compare-op may be one of:    EQU - equal    NEQ - not equal    LSS - less than    LEQ - less than or equal    GTR - greater than    GEQ - greater than or equaland the /I switch, if specified, says to do case insensitive stringcompares.  The /I switch can also be used on the string1==string2 formof IF.  These comparisons are generic, in that if both string1 andstring2 are both comprised of all numeric digits, then the strings areconverted to numbers and a numeric comparison is performed.The CMDEXTVERSION conditional works just like ERRORLEVEL, except it iscomparing against an internal version number associated with the CommandExtensions.  The first version is 1.  It will be incremented by one whensignificant enhancements are added to the Command Extensions.CMDEXTVERSION conditional is never true when Command Extensions aredisabled.The DEFINED conditional works just like EXIST except it takes anenvironment variable name and returns true if the environment variableis defined.%ERRORLEVEL% will expand into a string representation ofthe current value of ERRORLEVEL, provided that there is not alreadyan environment variable with the name ERRORLEVEL, in which case youwill get its value instead.  After running a program, the followingillustrates ERRORLEVEL use:    goto answer%ERRORLEVEL%    :answer0    echo Program had return code 0    :answer1    echo Program had return code 1You can also use numerical comparisons above:    IF %ERRORLEVEL% LEQ 1 goto okay%CMDCMDLINE% will expand into the original command line passed toCMD.EXE prior to any processing by CMD.EXE, provided that there is notalready an environment variable with the name CMDCMDLINE, in which caseyou will get its value instead.%CMDEXTVERSION% will expand into a string representation of thecurrent value of CMDEXTVERSION, provided that there is not alreadyan environment variable with the name CMDEXTVERSION, in which case youwill get its value instead. 
Edited by crashfly
Link to comment
Share on other sites

Hi crashfly,

 

Sorry about that small mistake EXISTS instead of EXIST. 

This is only when explaining my problem. 

my config.js file is correctely spelled.

 

Any idea of the reason of the trouble

 

Edit:  Just noticed, you need to drop the "S" on your "EXISTS" part.  See below for the other part of my post.

-----------------------

Try using the command "if /?", you get the following:

Link to comment
Share on other sites

You can try:

cmds[pn]=['"%systemdrive%\\Folder_Name\\MainExe.exe" /s /v/qn'];cond[pn]=['FileExists("C:\\Folder_Name\\MainExe.exe")'];
Change Folder_Name with the location folder name!

hello,

 

This is not the problem I want to solve.

MainExe.exe is always present if the program has to be installed

ExeFile.exe is a patch that if present should be installed.

That's why the IF EXIST statement.

 

 

I track down something !

 

A change I made, long time ago in "installer.js" file

 

Around line 1080, I added the following block.

 

case 'CMD': 
                                cmd="CMD /C " + cmd; 
                                fsoCmd=true; 
                                break;
 
Is that correct ?
May be that should be added definitely ?
 
Gilles 
Link to comment
Share on other sites

I think the cmd isn't being interpreted correctly, at least the command conditions are not.  Also there's an extra space at the end.

ExeFile.exe" /s /v/qn{ }'];

 

There is an easier way:

 

cmds[pn]=['{START} "Title" /WAIT "%wpipath%\\PathToExe\\ExeFile.exe" /s /v/qn'];cond[pn]=['FileExists("%wpipath%\\PathToExe\\MainExe.exe")']; 

 

 

 
 
Link to comment
Share on other sites

  • 2 months later...

Hi All

 

I do confirm with WPI 8.6.3 the proper fix is to change "installer.js"

 


Around line 1080, I added the following block.

 

case 'CMD': 
                                cmd="CMD /C " + cmd; 
                                fsoCmd=true; 
                                break;
 
Regards.
 
Gilles 

 

Link to comment
Share on other sites

Thanks, but already exist insde installer.js (line: 1207):

 

if (cmd.indexOf(".cmd") != -1 || cmd.indexOf(".bat") != -1)        {                if (cmd.indexOf(" ") != -1 && cmd.substr(0,1) != '"')                        cmd='"'+cmd+'"';                if (programs[item].bit64=="yes" && OSBits==64)                        cmd='"'+sysPath64+'cmd.exe" /C '+cmd;                else                        cmd='"'+sysPath32+'cmd.exe" /C '+cmd;                 return cmd;        }        if (cmd.indexOf(" ")==-1 && cmd.substr(0,1) != '"' && cmd.indexOf(">")==-1)     // > needed for stdout.  "d:\program.exe" "param1" >c:\app.txt                cmd='"'+cmd+'"';         return cmd;} 
Link to comment
Share on other sites

 

Hi All

 

I do confirm with WPI 8.6.3 the proper fix is to change "installer.js"

 

Around line 1080, I added the following block.

 

case 'CMD': 
                                cmd="CMD /C " + cmd; 
                                fsoCmd=true; 
                                break;
 
Regards.
 
Gilles 

 

 

 

OK, I found how to add the new CMD option!

 

You can also add Inside configwizard.js:

 

on line 365:

CommandsMenuBar.addNewChild("cmd_dos2", 11, "dos_cmd", "Cmd", false, "", "");

also on line 632:

case 'dos_cmd':	HandleCommandsSelectionMenu("{CMD} ");	break;

You will be able to choose option : {CMD}

 

Thanks to share if it's works for you!

 

Image

Edited by myselfidem
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...