7
$\begingroup$

Given Windows DOS command input:

tasklist|find /i "explorer.exe"

How to pass it to RunProcess or similar function and get the output?

$\endgroup$
7
$\begingroup$

RunProcess does not run shell commands (things you might type into your terminal). It runs processes, as the name suggests.

If you want to run shell commands, then you have these options:

  • Run (it does not give you the output)
  • Import["!yourcommand", "String"] or similar (to get the output)
  • Run your shell with RunProcess/StartProcess and pass the commands to it on its standard input. StartProcess has an example like this.
  • For this specific task, run cmd.exe with the /c flag and tell it what to execute. RunProcess has an example like this.
$\endgroup$
  • $\begingroup$ Thanks! but why RunProcess[{"cmd", "/c", " tasklist | find /i \"explorer.exe\""}] does not work? $\endgroup$ – Jerry Nov 22 '18 at 10:00
  • 1
    $\begingroup$ Import["! tasklist | find /i \"explorer.exe\"", "String"] works! ;) $\endgroup$ – Jerry Nov 22 '18 at 10:02
  • $\begingroup$ @Jerry I don't know how to get the quoting right. I do not use Windows. $\endgroup$ – Szabolcs Nov 22 '18 at 10:12
  • 2
    $\begingroup$ It's already solved using Import, thanks for help! $\endgroup$ – Jerry Nov 22 '18 at 10:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.