Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6914205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:19:02+00:00 2026-05-27T09:19:02+00:00

I am trying to run commands on Windows via NodeJS child processes: var terminal

  • 0

I am trying to run commands on Windows via NodeJS child processes:

var terminal = require('child_process').spawn('cmd');

terminal.stdout.on('data', function (data) {
    console.log('stdout: ' + data);
});

terminal.stderr.on('data', function (data) {
    console.log('stderr: ' + data);
});

terminal.on('exit', function (code) {
    console.log('child process exited with code ' + code);
});

setTimeout(function() {
    terminal.stdin.write('echo %PATH%');
}, 2000);

When it calls ti.stdin.write, it writes it to the stdin descriptor, but how do I trigger cmd to react at this point? How do I send the “enter” key signal that you do when you are actually typing in command prompt? Currently I get no response from cmd.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:19:02+00:00Added an answer on May 27, 2026 at 9:19 am

    Sending a newline \n will exectue the command. .end() will exit the shell.

    I modified the example to work with bash as I’m on osx.

    var terminal = require('child_process').spawn('bash');
    
    terminal.stdout.on('data', function (data) {
        console.log('stdout: ' + data);
    });
    
    terminal.on('exit', function (code) {
        console.log('child process exited with code ' + code);
    });
    
    setTimeout(function() {
        console.log('Sending stdin to terminal');
        terminal.stdin.write('echo "Hello $USER. Your machine runs since:"\n');
        terminal.stdin.write('uptime\n');
        console.log('Ending terminal session');
        terminal.stdin.end();
    }, 1000);
    

    The output will be:

    Sending stdin to terminal
    Ending terminal session
    stdout: Hello root. Your machine runs since:
    stdout: 9:47  up 50 mins, 2 users, load averages: 1.75 1.58 1.42
    child process exited with code 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to run commands straight through the CMD on Windows (Terminal on Linux).
I'm using Java 1.6 , Eclipse , Windows 7. I'm trying to run commands
I'm trying to run various commands using psexec.exe from Windows Sysinternals . What I
I'm trying to run javascript from a windows command line via script cscript //NoLogo
I'm trying to run a java process via Powershell in Windows XP. Here's the
I'm trying to run console commands via subprocess.Popen , and whenever I run it
I'm trying to run some commands in paralel, in background, using bash. Here's what
I'm trying to run powershell commands through a web interface (ASP.NET/C#) in order to
I'm trying to run the following commands: replace -x must A2input.txt replace -x a
I'm trying to run an interactive command through paramiko. The cmd execution tries to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.