I created a very simple script for exercising purposes. I simply try to output the result of my command myshell.run "tasklist | find 'cmd.exe'"
. But it fails with an error message. The error message is german 'Anweisungsende erwartet' in english it should mean 'statement completion expected'
set myshell = CreateObject("WScript.Shell")
myvar = ""
myvar = myshell.run "tasklist | find 'cmd.exe'"
MsgBox "Output = " & myvar
I expect output like this:
cmd.exe 5076 Console 1 3.156 K
Update:
I tried it again with the information on the link of the possible duplicate.
I have to use Exec
instead of Run
Set objShell = WScript.CreateObject("WScript.Shell")
Set objExecObject = objShell.Exec("cmd /C tasklist | find 'cmd.exe'")
strText = ""
Do While Not objExecObject.StdOut.AtEndOfStream
strText = strText & objExecObject.StdOut.ReadLine()
Loop
Wscript.Echo strText
Result: No output, even though the cmd.exe is running. I think it is not possible to execute it if there is a pipe symbol. If i use only cmd /C tasklist
then it outputs all the tasks.