簡體   English   中英

節點中的子進程未獲取正確的PID ID

[英]child process in node is not getting the correct PID id

當我嘗試生成批處理文件時,沒有獲得該child proces的正確PID

當我嘗試殺死子進程的PID時,正在運行的進程沒有停止,並且停止了另一個cmd

我不知道這是怎么回事。

在我的批處理文件中,正在打開另一個cmd ,並將目錄更改為C:\\AppiumForWindows-1.0.0\\Appium\\node_modules\\appium\\bin並運行node進程node appium

.i我想在單獨的cmd執行該node進程(盡管生成該batch文件時,它將使用相同的腳本執行。我不需要那個。)這就是我使用單獨的cmd的原因。

由於這個原因使我感到困惑,因為沒有獲得該進程的正確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文件

@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

在運行tasklist它顯示具有多個PID的cms,我試圖一一殺死並在一個PID殺死正在運行的batch文件進程。

從子進程ID獲取PID不會終止正在運行的批處理進程。 請為此提出解決方案。

您無法殺死pid,因為它是整數。 您想殺死生成的進程

start.kill();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM