How to use child_process to execute multi commands? - node.js

I want to use spawn to execute like
cd ../ && ls
I tried
const { spawn } = require('child_process');
spawn('cd', ['../', '&&', 'ls'], {
stdio: 'inherit',
});
But failed with:
Error: spawn cd ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:240:19)
at onErrorNT (internal/child_process.js:415:16)
at process._tickCallback (internal/process/next_tick.js:63:19)
at Function.Module.runMain (internal/modules/cjs/loader.js:834:11)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
Emitted 'error' event at:
at Process.ChildProcess._handle.onexit (internal/child_process.js:246:12)
at onErrorNT (internal/child_process.js:415:16)
[... lines matching original stack trace ...]
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
I've googled for this problem for a while, but got no good idea, please help me...

&& is a shell operator. In order to use it, you'll need to specify shell: true when spawning, and have the entire "chain" as a command, not as arguments:
const { spawn } = require('child_process');
spawn('cd .. && ls', {
shell: true,
stdio: 'inherit',
});

Related

close window (node js)

I want it to end Roblox but I cant get it to work
The code I found
exec('tasklist', (err, out, code) => {
const id = processIdFromTaskList("RobloxPlayerBeta.exe", out);
process.kill(id, "SIGKILL");
});
Node = v18.13.0
The error I get:
[Error_Handling] :: Uncaught Exception/Catch (MONITOR)
ReferenceError: processIdFromTaskList is not defined
at D:\Js\Natro-macro-control-Testing\Commands\Control\close.js:15:16
at ChildProcess.exithandler (node:child_process:411:7)
at ChildProcess.emit (node:events:513:28)
at maybeClose (node:internal/child_process:1091:16)
at ChildProcess._handle.onexit (node:internal/child_process:302:5) uncaughtException
[Error_Handling] :: Uncaught Exception/Catch
ReferenceError: processIdFromTaskList is not defined
at D:\Js\Natro-macro-control-Testing\Commands\Control\close.js:15:16
at ChildProcess.exithandler (node:child_process:411:7)
at ChildProcess.emit (node:events:513:28)
at maybeClose (node:internal/child_process:1091:16)
at ChildProcess._handle.onexit (node:internal/child_process:302:5) uncaughtException

Error: spawn ./node_modules/.bin/webpack ENOENT

root#ubuntu:/var/www/pterodactyl# yarn build:production
yarn run v1.22.19
$ yarn run clean && cross-env NODE_ENV=production ./node_modules/.bin/webpack --mode production
$ cd public/assets && find . ( -name ".js" -o -name ".map" ) -type f -delete
node:events:491
throw er; // Unhandled 'error' event
^
Error: spawn ./node_modules/.bin/webpack ENOENT
at ChildProcess._handle.onexit (node:internal/child_process:283:19)
at onErrorNT (node:internal/child_process:476:16)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Emitted 'error' event on ChildProcess instance at:
at ChildProcess._handle.onexit (node:internal/child_process:289:12)
at onErrorNT (node:internal/child_process:476:16)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
errno: -2,
code: 'ENOENT',
syscall: 'spawn ./node_modules/.bin/webpack',
path: './node_modules/.bin/webpack',
spawnargs: [ '--mode', 'production' ]
}
Node.js v18.10.0
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

mac os, after npm update I get strange errors, when I open a terminal

When I start new terminal - I see the error.
I press Enter - and then I can work normally.
Why this happens and how to fix this?
apower ~/Desktop/t1 node:events:505
throw er; // Unhandled 'error' event
^
Error: write EPIPE
at afterWriteDispatched (node:internal/stream_base_commons:160:15)
at writeGeneric (node:internal/stream_base_commons:151:3)
at Socket._writeGeneric (node:net:823:11)
at Socket._write (node:net:835:8)
at writeOrBuffer (node:internal/streams/writable:390:12)
at _write (node:internal/streams/writable:331:10)
at Writable.write (node:internal/streams/writable:335:10)
at SafeSubscriber._next (/usr/local/lib/node_modules/#angular/cli/node_modules/#angular-devkit/core/node/cli-logger.js:52:20)
at SafeSubscriber.__tryOrUnsub (/usr/local/lib/node_modules/#angular/cli/node_modules/rxjs/internal/Subscriber.js:205:16)
at SafeSubscriber.next (/usr/local/lib/node_modules/#angular/cli/node_modules/rxjs/internal/Subscriber.js:143:22)
Emitted 'error' event on Socket instance at:
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
errno: -32,
code: 'EPIPE',
syscall: 'write'
}
Node.js v18.2.0
apower ~/Desktop/t1
apower ~/Desktop/t1 npm -v
8.12.1
apower ~/Desktop/t1 node -v
v18.2.0

Laravel 8 and JetStream npm run dev error in windows

npm run dev
cmd error
[enter image description henter image description hereere]2
node:events:498
throw er; // Unhandled 'error' event
^
Error: write EIO
at afterWriteDispatched (node:internal/stream_base_commons:160:15)
at writeGeneric (node:internal/stream_base_commons:151:3)
at WriteStream.Socket._writeGeneric (node:net:795:11)
at WriteStream.Socket._write (node:net:807:8)
at writeOrBuffer (node:internal/streams/writable:389:12)
at _write (node:internal/streams/writable:330:10)
at WriteStream.Writable.write (node:internal/streams/writable:334:10)
at LogUpdate.write (C:\wamp64\www\hospital_app\node_modules\webpackbar\dist\index.cjs:1384:35)
at LogUpdate.render (C:\wamp64\www\hospital_app\node_modules\webpackbar\dist\index.cjs:1374:10)
at FancyReporter._renderStates (C:\wamp64\www\hospital_app\node_modules\webpackbar\dist\index.cjs:1456:15)
Emitted 'error' event on WriteStream instance at:
at emitErrorNT (node:internal/streams/destroy:157:8)
at emitErrorCloseNT (node:internal/streams/destroy:122:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
errno: -4070,
code: 'EIO',
syscall: 'write'
node and npm version are
C:\wamp64\www\hospital_app>node -v
v16.14.0
C:\wamp64\www\hospital_app>npm -v
8.3.1
pls help me to solve this ?

azure-functions-core-tools : while running "func init" command fails

On executing 'func init' command from an empty directory to create a azure function fails with following error:
events.js:298
throw er; // Unhandled 'error' event
^
Error: spawn C:\Users\<XYZ>\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin/func ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)
at onErrorNT (internal/child_process.js:467:16)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
Emitted 'error' event on ChildProcess instance at:
at Process.ChildProcess._handle.onexit (internal/child_process.js:273:12)
at onErrorNT (internal/child_process.js:467:16)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
errno: -4058,
code: 'ENOENT',
syscall: 'spawn C:\\Users\\<XYZ>\\AppData\\Roaming\\npm\\node_modules\\azure-functions-core-tools\\bin/func',
path: 'C:\\Users\\<XYZ>\\AppData\\Roaming\\npm\\node_modules\\azure-functions-core-tools\\bin/func',
spawnargs: [ 'init' ]
}
Anyone any suggestions on the same?
Thanks for the update #silent .
Googling the same, I also did land into the same link.
To followup on the suggestions at the Github, I had to perform following steps:
Go to the folder:
C:\Users\< XYZ >\AppData\Roaming\npm\node_modules\azure-functions-core-tools
Open the package.json file in an editor
Modify the version for "unzipper" module under dependencies from '0.10.5' to '0.10.8'.
"dependencies": {
"chalk": "3.0.0",
"command-exists": "1.2.8",
"glob": "7.1.6",
"https-proxy-agent": "3.0.1",
"progress": "2.0.3",
"rimraf": "3.0.0",
"tmp": "0.1.0",
"unzipper": "0.10.8"
},
Delete "node_modules" folder under this directory.
Run "npm install" command from this directory on command-prompt.
Remember to replace "< XYZ >" with your own Username on the machine.

Resources