1

I've been trying for hours to execute the following Inno Script code.

Exec('C:\Windows\System32\inetsrv\appcmd.exe', 'list site > "c:\test\temp.txt"', '', SW_SHOW, ewWaitUntilTerminated, ResultCode)

It executes the appcmd program whose output is saved in a file. The above code doesn't stream the output into a file when run from Inno Script. When I run the code from command line, it works fine. I can also execute the other commands like ipconfig and redirect the output to the file.

I've also tried the following code but to no avail.

 Exec('cmd.exe', '"/c "C:\Windows\System32\inetsrv\appcmd.exe" list site > "c:\test\temp.txt"', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) 

I can run other commands like add site or add apppool. I can see that the cmd window opens but since opening and closing is almost instantaneous, I can't check the output on the window.

The return value of Exec is True.

I'm not exactly sure what is going wrong as I am not getting any error while executing the code.

h-rai
  • 3,636
  • 6
  • 52
  • 76
  • Basically, if you made it working with `ipconfig.exe`, you must have executed it via `cmd.exe`. So execute the `appcmd.exe` the same way as `ipconfig.exe`. – Martin Prikryl Jan 13 '16 at 06:51
  • @MartinPrikryl That's where i looked before I posted this. Exactly, it should have worked. But I'm stumped why this isn't working for appcmd.exe while it's working for cmd.exe – h-rai Jan 13 '16 at 21:58
  • When I wrap up the code `C:\Windows\System32\inetsrv\appcmd.exe list sites > c:\civica\test.txt` in a bat file and call that batch file, it seems to work. But isn't that the same thing as executing appcmd from Inno script. Any idea why? @MartinPrikryl – h-rai Jan 14 '16 at 00:05
  • @MartinPrikryl Also, if i execute other commands like `add site` then it executes the command successfully. I think it's the output redirection that isn't working. – h-rai Jan 14 '16 at 00:18
  • But in your question you are **not** executing the `appcmd.exe` via `cmd.exe`. If you have tried that, show us the code for that. The code in your question is wrong. – Martin Prikryl Jan 14 '16 at 07:05
  • @MartinPrikryl I meant manually opening command prompt, navigating to the inetsrv folder and typing in the required command like `appcmd list sites > c:\temp\test.txt`. – h-rai Jan 14 '16 at 22:33
  • You have quotes wrong. This is correct: `Exec('cmd.exe', '/c ""C:\Windows\System32\inetsrv\appcmd.exe" list site > "c:\test\temp.txt""', ...` And of course, use constants (`{cmd}`, `{sys}`, `{tmp}`), where appropriate. – Martin Prikryl Jan 15 '16 at 06:54
  • Thanks, that did the trick. Surprisingly enough, when I run the appcmd.exe instead of cmd, the output doesn't redirect to a file. I guess I will just use cmd. @MartinPrikryl – h-rai Jan 17 '16 at 22:55
  • It's not surprising. The output redirection (the `>` symbol) is a feature of the `cmd.exe`. So you have to use it, if you need to redirect the output using `>`. When you are on Windows command-line, you are running the command within `cmd.exe` already (The Windows command-line window in the `cmd.exe`). – Martin Prikryl Jan 18 '16 at 06:56
  • How do I accept the duplicate? – h-rai Jan 18 '16 at 23:32
  • You should see "That solved my problem" button. See http://meta.stackexchange.com/questions/250981/new-ui-encourages-askers-to-confirm-or-dispute-duplicate-votes – Martin Prikryl Jan 19 '16 at 06:53
  • I don't have any such button to accept the duplicate. – h-rai Jan 20 '16 at 03:32

0 Answers0