Archive: nsExec got a serious problem?


nsExec got a serious problem?
Hi there!

I just tried to execute a small app I wrote which spawns a XCopy (spawnlp) - when I execute it with ExecWait everything works fine but if I try to use nsExec nothing happens ... it that possible just because I'm creating another child process in my app?

It's not very urgent but very strange isn't it? :eek:


Please post details and script code.


This is the working script code:

SetOutPath "$INSTDIR\${TOOL_TYPE_DIR}\${SW_TOOLS_DIR}"
File "${SOURCE_BASE_DIR}\${TOOL_TYPE_DIR}\${SW_TOOLS_DIR}\Backup.exe"
ExecWait "$INSTDIR\${TOOL_TYPE_DIR}\${SW_TOOLS_DIR}\Backup.exe $INSTDIR\${TOOL_TYPE_DIR}"

If I replace ExecWait with nsExec::Exec nothing happens :(

What more details do you need?


Are you sure the application does not start, or is there nothing on the screen?

You should get the nsExec return value from the stack to see what happends.


or try the modified version here with the ExecToLog option to see if the application is running, if it is then you should see an indicator going around

-daz


There are a few major faults with the execution line to start with.

"$\"$INSTDIR\${TOOL_TYPE_DIR}\${SW_TOOLS_DIR}\Backup.exe$\" $\"$INSTDIR\${TOOL_TYPE_DIR}$\""

If $INSTDIR or other paths in the string have spaces, then the file may not be executed, and the parameters will become two or more parameters instead of one.

Use:
"$\"$INSTDIR\${TOOL_TYPE_DIR}\${SW_TOOLS_DIR}\Backup.exe$\" $\"$INSTDIR\${TOOL_TYPE_DIR}$\""

-Stu


Is not better to explain with single quotes (')? (I know, is the same thing, but appear more "clean")

'"$INSTDIR\${TOOL_TYPE_DIR}\${SW_TOOLS_DIR}\Backup.exe" "$INSTDIR\${TOOL_TYPE_DIR}"'


hi again - some news for this issue..

I just tried using ExecToLog and found the following output in my log:
Wait Until backup is finished...
Backup created in: "C:\Backups\Backup20031020-083352"

That's output from my exe but no backup was created - not even the directory!

Here is the source of my exe - I'm using a xcopy to create the directory as you can see in the last line in main()

void main(int argc, char* argv[])
{
SYSTEMTIME st;
int i;
HANDLE hStdOut;
COORD dwSize;


if(argc < 2)
{
printf("USAGE: SEZBackup c:\\CDS323\n");
printf(" or SEZBackup c:\\SP323\n");
printf(" got the idea?\n");
exit(1);
}
strcpy(szBackupSourceDirectory,argv[1]);

// Build Backup Directory Name
GetLocalTime(&st);
sprintf(szBackupTargetDirectory,"C:\\Backups\\Backup%04d%02d%02d-%02d%02d%02d",st.wYear,st.wMonth,st.wDay,st.wHour,st.wMinute,st.wSecond);

SetConsoleTitle("Backup Started...");
printf("Wait Until backup is finished...\n");

//////////////////////////////////////////////
// Set Screen Buffer size of Handler window //
//////////////////////////////////////////////
hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
if (hStdOut != INVALID_HANDLE_VALUE)
{
dwSize.X = 50;
dwSize.Y = 3;
SetConsoleScreenBufferSize(hStdOut, dwSize);
}
printf("Backup created in: \"%s\"\n",szBackupTargetDirectory);
i=_spawnlp( _P_WAIT, "Xcopy.exe", "Xcopy.exe", szBackupSourceDirectory, szBackupTargetDirectory,"/V","/Q","/E","/I","/H","/R", NULL);
}

I'll now to use exec instead of _spawnlp maybe this will help ...


_execlp and _execlpe also didn't help!


Why use an external program for something NSIS can do? Use CopyFiles. If you really want XCopy you can use it from NSIS too. Just use nsExec to execute it so you won't get a console window.

To get the date you can use nsisdt from the Archive's download page or a System.dll call (Archive has some examples for that one I think. If not, there are some in the forum).


thx kichik for the hint - I wrote this app just because I didn't know how to get the actual timestamp for the directory - I tried using nsisdt but I only got this -> "Error: The file you requested could not be found!"

.. but even thou there is a problem with nsExec I believe


Are you sure the filename is correct (add a dir too)?


also it seems that you never test the value of i to determine if the process that you're trying to run was succesfully called or not.

saying that since you do the printf("Backup created in: \"%s\"\n",szBackupTargetDirectory); before anything has been done.

-daz


Yes I'm really sure that all paths and filenames are correct because if I replace nsexec::ExecToLog with ExecWait everything works fine

I also disabled the silent mode of xcopy and with ExecToLog I got no more output in the log than i posted above but I should get at least one line for each copied file!

@Joost
Sorry I forgot to mention that I got this message when trying to download the zip file from the archive server :rolleyes:


can you post an example to work with?

-daz


Try downloading again. Somehow all of the files got deleted :(


@kichik
downloads are now working fine - thx

@DrO
If attached the source of the backup tool (Backup.zip) and here is a part of my script where i do the call

Section "-CreateBackupSection"
;SectionIn RO

CreateDirectory "$INSTDIR\${TOOL_TYPE_DIR}\${RestoreRegistry_DIR}"

; Registry
nsExec::ExecToLog "regedit /e /s $INSTDIR\${TOOL_TYPE_DIR}\${RestoreRegistry_DIR}\RollbackRegistry.txt HKEY_LOCAL_MACHINE\${SEZ_REG_ROOTKEY}"

SetOutPath "$INSTDIR\${TOOL_TYPE_DIR}\${SW_TOOLS_DIR}"
File /r "${SOURCE_BASE_DIR}\${TOOL_TYPE_DIR}\${SW_TOOLS_DIR}\SEZBackup.exe"
ExecWait "$INSTDIR\${TOOL_TYPE_DIR}\${SW_TOOLS_DIR}\SEZBackup.exe $INSTDIR\${TOOL_TYPE_DIR}"

; delete Rollback.exe in Instdir
Delete "$INSTDIR\${TOOL_TYPE_DIR}\Rollback.exe"
RMDir /r "$INSTDIR\${TOOL_TYPE_DIR}\${RestoreRegistry_DIR}"

SectionEnd


zwuba is right, there does seem to be a problem with nsExec.

i tried the code posted and it is fine when run under Execwait but when you run it under nsExec there is no output seen from xcopy (i even tried just doing "xcopy /?" in ExecToLog(..) and nothing came out :eek: ).

will check things more as to what the processes in nsExec are doing as soon as i can.

-daz