test
This commit is contained in:
parent
b370169aaf
commit
9389d41364
@ -110,10 +110,11 @@ swarm.on('connection', (peer) => {
|
|||||||
case 'dockerCommand':
|
case 'dockerCommand':
|
||||||
console.log(`[INFO] Executing Docker CLI command: ${parsedData.data}`);
|
console.log(`[INFO] Executing Docker CLI command: ${parsedData.data}`);
|
||||||
try {
|
try {
|
||||||
const exec = spawn('sh', ['-c', parsedData.data]); // Use `spawn` to execute the Docker command
|
const exec = spawn('sh', ['-c', parsedData.data]); // Use spawn to run the Docker command
|
||||||
|
|
||||||
|
// Handle stdout (command output)
|
||||||
exec.stdout.on('data', (output) => {
|
exec.stdout.on('data', (output) => {
|
||||||
console.log(`[DEBUG] Command output: ${output.toString()}`); // Log the command output
|
console.log(`[DEBUG] Command output: ${output.toString()}`);
|
||||||
peer.write(
|
peer.write(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
type: 'dockerOutput',
|
type: 'dockerOutput',
|
||||||
@ -123,8 +124,9 @@ swarm.on('connection', (peer) => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Handle stderr (errors)
|
||||||
exec.stderr.on('data', (error) => {
|
exec.stderr.on('data', (error) => {
|
||||||
console.error(`[ERROR] Command error output: ${error.toString()}`); // Log any errors
|
console.error(`[ERROR] Command error output: ${error.toString()}`);
|
||||||
peer.write(
|
peer.write(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
type: 'dockerOutput',
|
type: 'dockerOutput',
|
||||||
@ -134,6 +136,7 @@ swarm.on('connection', (peer) => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Handle command completion
|
||||||
exec.on('close', (code) => {
|
exec.on('close', (code) => {
|
||||||
console.log(`[INFO] Command exited with code: ${code}`);
|
console.log(`[INFO] Command exited with code: ${code}`);
|
||||||
peer.write(
|
peer.write(
|
||||||
|
Loading…
Reference in New Issue
Block a user