简体   繁体   中英

child process in node is not getting the correct PID id

while i trying to spawn a batch file am not getting the correct PID of that child proces s.

when i tried to kill the PID of the child process ,the running process is not stoping and it stops another cmd

i dont know how it is happening.

in my batch file am doing to open another cmd and change the directry to C:\\AppiumForWindows-1.0.0\\Appium\\node_modules\\appium\\bin and run a node process node appium

.i want to execute that node process in seperate cmd (While spawning that batch file it will execute with the same script .i don't need that.)that's what i use separate cmd.

Am confusing due this reason am not getting the correct PID of that process?i don't know...

var startappium = function (dev, callback) {
  var ports = {};
  var execCmd = __dirname+"//Start.bat"; 

   var args = ['1000']; 
   var start = spawn(execCmd, args);
   console.log("pid id----------------------",start.pid)  
   var pid =start.pid 
   start.stdout.on('data', function (d) {
    setTimeout(function() {
    start .kill()    // it does not kill the process
     },5000);   
   console.log(d.toString())
   return callback(null, ports); 
   });
   start.stderr.on('data', function (ta) {  
      return callback(null, ta); 
  });
  start.on('close', function (code) {  
     console.log("close: ",code)
  });
}
startappium()

Start.bat file

@echo off
start cmd /k " call "C:\Program Files\nodejs\nodevars.bat" & pushd C:\AppiumForWindows-1.0.0\Appium\node_modules\appium\bin && node appium -p %1 --chromedriver-port %2" 
pause

while running tasklist it shows cms with several PID 's and i tried to kill one by one and killed that running batch file process in one PID .

PID getting from the child process id not killing the batch process running. Please suggest a solution for this.

You can't kill a pid as it's an integer. You want to kill the spawned process :

start.kill();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM