简体   繁体   English

节点中的子进程未获取正确的PID ID

[英]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. 当我尝试生成批处理文件时,没有获得该child proces的正确PID

when i tried to kill the PID of the child process ,the running process is not stoping and it stops another cmd 当我尝试杀死子进程的PID时,正在运行的进程没有停止,并且停止了另一个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 在我的批处理文件中,正在打开另一个cmd ,并将目录更改为C:\\AppiumForWindows-1.0.0\\Appium\\node_modules\\appium\\bin并运行node进程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. .i我想在单独的cmd执行该node进程(尽管生成该batch文件时,它将使用相同的脚本执行。我不需要那个。)这就是我使用单独的cmd的原因。

Am confusing due this reason am not getting the correct PID of that process?i don't know... 由于这个原因使我感到困惑,因为没有获得该进程的正确PID ?我不知道...

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 Start.bat文件

@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 . 在运行tasklist它显示具有多个PID的cms,我试图一一杀死并在一个PID杀死正在运行的batch文件进程。

PID getting from the child process id not killing the batch process running. 从子进程ID获取PID不会终止正在运行的批处理进程。 Please suggest a solution for this. 请为此提出解决方案。

You can't kill a pid as it's an integer. 您无法杀死pid,因为它是整数。 You want to kill the spawned process : 您想杀死生成的进程

start.kill();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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