Im trying to run a C file using child process in node.js. Im using execFile to do this, the 'test' file is in the same folder. The same program runs on linux and gives the output but doesn't run on windows. It shows error: spawn ./test ENONET
on windows. What do I do?
const { execFile } = require('child_process')
execFile('./test', (error, stdout, stderr) => {
if(error) {
console.log(`error: ${error.message}`)
return
}
if(stderr) {
console.log(`stderr: ${stderr}`)
}
console.log(`stdout: ${stdout}`) })
Edit: I tried it with this file 'somefile.sh' which is in the same directory
#!/bin/bash
//ls -lh //for linux
-dir //for windows
It shows
Error: spawn UNKNOWN
←[90m at ChildProcess.spawn (internal/child_process.js:403:11)←[39m
←[90m at spawn (child_process.js:553:9)←[39m
←[90m at execFile (child_process.js:237:17)←[39m
at Object.<anonymous> (C:\Users\Dell\Desktop\Projects\childprocess\exec_file.js:6:1)
←[90m at Module._compile (internal/modules/cjs/loader.js:1063:30)←[39m
←[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)←[39m
←[90m at Module.load (internal/modules/cjs/loader.js:928:32)←[39m
←[90m at Function.Module._load (internal/modules/cjs/loader.js:769:14)←[39m
←[90m at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)←[39m
←[90m at internal/main/run_main_module.js:17:47←[39m {
errno: ←[33m-4094←[39m,
code: ←[32m'UNKNOWN'←[39m,
syscall: ←[32m'spawn'←[39m
}
I also tried for exec using a single command and it gives the output for the below code.
const {exec} = require('child_process')
exec('pwd', (error, stdout, stderr) => {
if(error) {
console.log(`error: ${error.message}`)
return
}
if(stderr) {
console.log(`stderr: ${stderr}`)
}
console.log(`stdout: ${stdout}`)
})
Output shows the present working direactory. This is the tutorial I referred: https://www.youtube.com/watch?v=bbmFvCbVDqo&t=441s