bun icon indicating copy to clipboard operation
bun copied to clipboard

`exec` and `execSync` do not properly parse the given string command (tested only on Windows)

Open Seblor opened this issue 2 years ago • 0 comments

What version of Bun is running?

1.1.2+c4847f464

What platform is your computer?

Microsoft Windows NT 10.0.19045.0 x64

What steps can reproduce the bug?

Here is a snippet to reproduce the error:

import { exec, execSync } from "child_process";

const process = exec(`tasklist /FI "IMAGENAME eq chrome.exe"`)

console.log(process.spawnargs);

console.log(execSync(`tasklist /FI "IMAGENAME eq chrome.exe"`).toString());

What is the expected behavior?

Here is Node's output:

[
  'C:\\Windows\\system32\\cmd.exe',
  '/d',
  '/s',
  '/c',
  '"tasklist /FI "IMAGENAME eq chrome.exe""'
]

Image Name                     PID Session Name        Session#    Mem Usage
========================= ======== ================ =========== ============
chrome.exe                   14468 Console                    1    607,384 K
chrome.exe                   31712 Console                    1      9,512 K
chrome.exe                   11100 Console                    1    292,768 K
chrome.exe                   31372 Console                    1     72,904 K
chrome.exe                    4632 Console                    1     24,992 K
[...]

What do you see instead?

Here is Bun's output:

[ "C:\\Windows\\system32\\cmd.exe", "/d", "/s", "/c", "tasklist /FI \"IMAGENAME eq chrome.exe\""
]
ERROR: Invalid argument/option - 'eq'.
Type "TASKLIST /?" for usage.
2 |
3 | const process = exec(`tasklist /FI "IMAGENAME eq chrome.exe"`)
4 |
5 | console.log(process.spawnargs);
6 |
7 | console.log(execSync(`tasklist /FI "IMAGENAME eq chrome.exe"`).toString());
                ^
error: ERROR: Invalid argument/option - 'eq'.
Type "TASKLIST /?" for usage.

   errno: -1
   code: "1"
 syscall: "spawnSync"
   path: "C:\Windows\system32\cmd.exe"

      at new SystemError (node:child_process:822:27)
      at node:child_process:164:47
      at node:child_process:213:45
      at D:\workspace\testing\temp.js:7:13

Additional information

No response

Seblor avatar Apr 06 '24 18:04 Seblor