Note that there are some explanatory texts on larger screens.

plurals
  1. POCalling Powershell with WshShell.Exec() method hangs the script
    primarykey
    data
    text
    <p>I am trying to call Powershell with the Exec method of the WshShell object. I am writing the script in JScript, but I have reproduced the problem in VBScript as well. Both of the following short test scripts will cause WSH to hang indefinitely:</p> <p>test.js</p> <pre><code>var shell = new ActiveXObject("WScript.Shell"); WScript.Echo(shell.exec("powershell -Command $Host.Version; Exit").StdOut.ReadAll()); </code></pre> <p>test.vbs</p> <pre><code>dim shell set shell = CreateObject("WScript.Shell") WScript.Echo shell.exec("powershell -Command $Host.Version; Exit").StdOut.ReadAll </code></pre> <p>Am I doing something wrong, or am I running into or a limitation/incompatibility? The Run method works very well, but I need to capture output, which it's not capable of doing.</p> <p>Edit: I forgot to mention that my platform is Windows 7 Pro, 64-bit with PowerShell 3. I've tested on Windows XP with PowerShell 1 as well.</p> <p>Edit 2: I've updated the test scripts that I'm running to fit with x0n's answer. Unfortunately, I'm still having trouble. Here are my current tests:</p> <p>test.js:</p> <pre><code>var shell = new ActiveXObject("WScript.Shell"); WScript.Echo(shell.exec('powershell -noninteractive -noprofile -Command "&amp; { echo Hello_World ; Exit }"').StdOut.ReadAll()); </code></pre> <p>test.vbs:</p> <pre><code>dim shell set shell = CreateObject("WScript.Shell") WScript.Echo shell.exec("powershell -noninteractive -noprofile -Command ""&amp; { echo Hello_World ; Exit }""").StdOut.ReadAll </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload