- NSIS Discussion
- ExecDos creates an empty file in $EXEDIR
Archive: ExecDos creates an empty file in $EXEDIR
820815
16th October 2009 05:08 UTC
ExecDos creates an empty file in $EXEDIR
I'm trying to make a GUI :rolleyes: for a console application.
The problem is that ExecDos creates an empty file with a random (?) number name in the $EXEDIR. :weird:
nsExec & ExecCmd haven't function "isDone", which is needed for further use.
Here's just an example script:
OutFile test.exe
>!include FileFunc.nsh
>!include LogicLib.nsh
>!include nsDialogs.nsh
Page custom window
>Var hwnd_func_load
>Function .onInit
InitPluginsDir
GetTempFileName $R3 $PLUGINSDIR
StrLen $R2 $EXEDIR
IntOp $R2 $R2+ 1
FunctionEnd
>Function window
nsDialogs
::Create 1018
>${NSD_CreateGroupBox} 0 0 100% 100% 'test'
>GetFunctionAddress $hwnd_func_load load
nsDialogs::CreateTimer $hwnd_func_load 1
nsDialogs::Show
FunctionEnd
>Function load
nsDialogs::KillTimer $hwnd_func_load
FileOpen $R1 $R3 w
>${Locate} '$EXEDIR' '/L=F /M=*.txt' writeLine
FileClose $R1
ExecDos::exec '$SYSDIR\\sort.exe "$R3" /o "$R3"'
>FunctionEnd
>Function writeLine
StrCpy $R8 $R8'' $R2
>${If} $R8 == ''
>FileWrite $R1 ' $R7$\r$\n'
>${Else}
>FileWrite $R1 '\$R8\$R7$\r$\n'
>${EndIf}
>Push $0
FunctionEnd
Section
SectionEnd
>
Any ideas? :confused:
MSG
16th October 2009 06:00 UTC
What exactly do you need/want to accomplish?
820815
16th October 2009 06:29 UTC
I just want to understand why these empty files are created and how can I fix it :)
Other functions and macros that goes after, doesn't matter, because they don't affect the bug.
Takhir
17th October 2009 09:51 UTC
First idea is to read ExecDos manual ;) http://nsis.sourceforge.net/ExecDos_plug-in
If you want to have a file with your application output, you must define 3 parameters in plug-in's command line. Now I see one only - this work if utility' output goes not to file, options are [/TOSTACK | /DETAILED | /TOWINDOW | /TOFUNC]. In your code plug-in gets some garbage from stack and creates output file in current folder with this name, but 'sort' utility probably not produces any output - this is why file is empty.
isDone may have sence with /ASYNC option only.
Very good idea is to check plug-in exit code (Pop) - this a) will give you info about operation complition; b) will remove exit code value from installer stack and subsequent stack operations will be more reliable.
820815
17th October 2009 13:21 UTC
I've read, but did not notice that 3 parameters are required :o
СпаÑибо ;)
ChocJunkie
10th November 2009 10:41 UTC
I've got a similar problem.
I want to write the output of the program I'm calling to a text file.
The installer executes and the file will be created, but then the installer remains in a infinite loop.
ExecDos::exec "wmic" "PATH Win32_DiskDrive WHERE InterfaceType!='USB' GET DeviceID /VALUE" "C:\test.txt"
Pop $R0
MessageBox MB_OK "Exit code $R0"
Any ideas what I'm doing wrong?
Thanks :)
CJ
ChocJunkie
10th November 2009 11:49 UTC
Ok, the task manager shows that wmic.exe is still running.
Any ideas why it doesn't end?
Using nsExec plugin wmic ends normally. But I'm not able to get the output of the function call in a file. If I'm using ">FILE" the call fails...
Anders
10th November 2009 13:19 UTC
nsExec runs the exe directly, you need to use %comspec% /c if you want redirection
Takhir
10th November 2009 13:24 UTC
See attached screenshot. You started wmic in a 'dialog' mode, so it waits for termination signal. BTW $\n required in stdin line if you want the string to be sent to application. But simplest way is to do everything in command line
ExecDos::exec "wmic PATH Win32_DiskDrive WHERE InterfaceType!='USB' GET DeviceID /VALUE" "" "$EXEDIR\stdout.txt"
Added: interesting situation, I could make it working with ExecCmd plug-in only (ExecCmd::exec "wmic PATH Win32_DiskDrive WHERE InterfaceType!='USB' GET DeviceID /VALUE >stdout.txt" "" "$EXEDIR\stdout.txt"). May be wmic require terminal emulation.
ChocJunkie
10th November 2009 14:04 UTC
Added: interesting situation, I could make it working with ExecCmd plug-in only (ExecCmd::exec "wmic PATH Win32_DiskDrive WHERE InterfaceType!='USB' GET DeviceID /VALUE >stdout.txt" "" "$EXEDIR\stdout.txt"). May be wmic require terminal emulation. [/B]
Yeah, it's kind of interesting. ^^'
I've tried your code and I thing it's working but the correct command would be:
ExecCmd::exec "wmic PATH Win32_DiskDrive WHERE InterfaceType!='USB' GET DeviceID /VALUE >stdout.txt"
The last two paramteres are not needed.
It's not the cleanest method - I think - but I'm really happy it's working. :) Thank you. :)