If in a terminal I run git flow release publish '1.0.0' it is executed successfully.
If I use child_process.spawn in a test.js and then run it with node ./test.js file it also works fine.
But when I use child_process.spawn inside VS Code extension it produces error
fatal: could not read Username for 'https://github.com': No such device or address
If I edit .git/config and add my name https//$myname#github.com...... then error is
fatal: could not read Password for 'https://github.com': No such device or address.
Here is my code same in test file and VS Code
const spawn = require("child_process").spawn;
let cmd = 'git';
let args = ['flow', 'release', 'publish', '0.2.8'];
// let args = ['flow', 'release', 'delete', '-f', '-r', '0.2.8'];
const child = spawn(cmd, args);
let stdout = [];
let stderr = [];
child.stdout?.on('data', (data) => {
console.log(`[gitflow] Stdout ${data}`);
stdout.push(data.toString());
});
child.stderr?.on('data', (data) => {
console.log(`[gitflow] Stderr ${data}`);
stderr.push(data.toString());
});
child.on('error', err => {
console.log(`[gitflow] Error "${cmd} ${args?.join(" ")}" returned`, err);
});
child.on('spawm', err => {
console.log(`[gitflow] Spawn "${cmd} ${args?.join(" ")}" returned`, err);
});
child.on('exit', code => {
console.log(`[gitflow] Exit "${cmd} ${args?.join(" ")} exited`, code);
});
child.on('close', retc => {
console.log(`[gitflow] Command "${cmd}"`, retc, stderr, stdout);
});
Related
I try to spawn git process but i got unexpected result. stdout pipe empty. while the stderr pipe only clonning directory info. it should output cloning directory then progress of clonning.
const { spawn } = require('child_process');
const subprocess = spawn('git', ['clone', 'https://github.com/expressjs/express.git'], {
cwd: 'C:/Software Development/git/bin'
});
subprocess.stdout.on('data', data => {
console.log('Body info: \n')
console.log(data.toString())
});
subprocess.stderr.on('data', data => {
console.log('Error info: \n')
console.log(data.toString())
})
I've a problem with displaying the progressbar of a process executed by child_process spawn in a discord bot.
CLI Output:
2021-09-16 16:11:03 Welcome to Minecraft Overviewer version 0.17.39 (2402e41)!
2021-09-16 16:11:03 Generating textures...
2021-09-16 16:12:52 Preprocessing...
2021-09-16 16:15:14 Rendering 228498 total tiles.
99% [===================================================================================================================================================================================================== ] 228494 17.65t/s eta 00h 00m 00s
2021-09-16 19:50:57 Rendering complete!
When using the child_process spawn I get every output except for the progressbar.
Node script:
const child_process = require('child_process');
const command = "python";
const arguments = ["./Minecraft-Overviewer/overviewer.py", "--config=./world.py"]
var child = child_process.spawn(command, arguments, {
encoding: 'utf8',
shell: true
});
child.on('error', (error) => {
message.channel.send('Error!\r\n' + error);
});
child.stdout.setEncoding('utf8');
child.stdout.on('data', (data) => {
data = data.toString();
message.channel.send(`STDOUT: ${data}`);
});
child.stderr.setEncoding('utf8');
child.stderr.on('data', (data) => {
message.channel.send(`DATA: ${data}`);
});
child.on('close', (code) => {
//Here you can get the exit code of the script
switch (code) {
case 0:
message.channel.send('Process exited.');
break;
}
});
Any ideas on how I can catch the progressbar as well?
Many thanks in advance!
I have written code to execute bat file using nodejs, but it is restricting me to place the bat file at the same location where package.json file is present and it is not accepting absolute path.
I am using the following code:
const { spawn } = require('child_process');
const bat = spawn('cmd.exe', ['/c','coma.bat']);
bat.stdout.on('data', (data) => {
console.log('data is : '+data.toString());
});
bat.stderr.on('data', (data) => {
console.error('error is : '+data.toString());
});
bat.on('exit', (code) => {
console.log(`Child exited with code ${code}`);
});
it accepts full path (if this is the question):
const { spawn } = require('child_process');
const bat = spawn('cmd.exe', ['/c','C:\\scripts\\somescript.bat']);
On button click I can open a command prompt using Node.js child process.
var child_process = require('child_process');
let command = `start cmd.exe /K "cd /D c:/Users && java"`
let process = child_process.spawn(command, [], { shell: true }) //use `shell` option
using above code I can open a command prompt and run Java command at specified location.
Now my question how can I do same process in background without opening command prompt (cmd) ?
Spawn has the cwd (Current Working Directory) option which you can point to open up the process.
var child_process = require('child_process');
let bin = 'java';
let cliArgs= ['-version'];
let options = {
spawn: true,
cwd: 'c:/Users'
}
let command = child_process.spawn(bin, cliArgs, options ) //use `shell` option
command.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
});
command.stderr.on('data', (data) => {
console.log(`stderr: ${data}`);
});
command.on('close', (code) => {
console.log(`child process exited with code ${code}`);
});
My python scripts returns some text on console while execution is going on, but when executed via child_process.spawn in node.js, stdout.on doesn't give me real-time output on console, instead stdout.on is executed when spawn process is about to end.
var spawn = require("child_process").spawn
var command = ['esx_trace.py', '-w', '28796829', '-v', '8496', '-i', '10.1.1.38', '-u', 'root', '-p', 'whatever', '-t', '5'];
var child = spawn('python', command);
child.stdout.on("data", function (data) {
console.log("spawnSTDOUT:", data.toString())
})
child.stderr.on("data", function (data) {
console.log("spawnSTDERR:", data.toString())
})
child.on("exit", function (code) {
console.log("spawnEXIT:", code.toString())
})