![](/img/trans.png)
[英]Can't spawn `gcloud app deploy` from a Node.js script on Windows
[英]node.js, windows 7, spawn chrome, can't set user-data-dir
我正在嘗試使用spawn
在Windows 7上使用node.js打開Google Chrome。 除了設置user-data-dir
之外,它似乎適用於所有參數。 但是,-- --user-data-dir
直接從命令行工作,並且如果我從node調用.cmd文件並將參數傳遞給它,它也可以工作。
Chrome在后台打開(顯示在任務管理器中),但瀏覽器窗口沒有打開,我必須在任務管理器中手動終止該進程才能結束它。
我沒有出現任何錯誤或任何問題的跡象。
這是我的節點代碼:
var spawn = require('child_process').spawn;
var exe = 'C:\\Program Files\\Google\\Chrome\\application\\chrome.exe';
//this does not work and gives no errors just starts chrome in the background but fails to open browser window
// var args = [
// '--user-data-dir=C:\\Windows\\Temp\\testingdir',
// 'http://www.google.com'
// ];
//actual output from running this through a .cmd file and echoing out the arguments
// --user-data-dir=C:\Windows\Temp\testingdir http://www.google.com
//running the above arguments through a .cmd file from nodejs or manually running them in the cli works
//this works from nodejs, other arguments work too, just not the --user-data-dir argument
// var args = ['http://www.google.com'];
chrome = spawn(exe, args);
chrome.stdout.on('data', function (data) {
console.log('stdout: ' + data);
});
chrome.stderr.on('data', function (data) {
console.log('stderr: ' + data);
});
chrome.on('exit', function (code) {
console.log('child process exited with code ' + code);
// chrome.kill();
});
正如您在注釋掉的代碼中看到的那樣,只要我不嘗試更改user-data-dir,它就可以工作。 我嘗試了不同的臨時目錄,並在臨時目錄中設置了對“所有人”的完全訪問權限,以防出現權限問題。
更新:我剛剛從v0.8.1更新到最新的v0.8.14,現在當它失敗時, on('exit', function())
實際上會返回一個代碼。
child process exited with code 20
我如何查找此代碼以了解其含義?
更新2我認為退出代碼20只是一次fl幸,因為我再也無法復制它了。 嘗試測試不同的東西有點麻煩,因為我必須記得每次都要殺死任務管理器中的chrome進程,以確保獲得相同的結果。 因此,它返回到與以前相同的結果,沒有錯誤,但沒有鑲邊窗口,並且某些正在運行的鑲邊進程必須手動終止。
更新3我只是將此腳本移至Ubuntu,並更改了exe和args以反映不同的文件結構,並且該腳本可在Ubuntu上使用。
exe = "/opt/google/chrome/google-chrome"
和
args = [
"http://www.google.com",
"--user-data-dir=/home/lotus/testdir"
];
因此,我可以確認這與Windows上的Chrome瀏覽器特別相關。
http://www.hiteksoftware.com/mize/Knowledge/articles/049.htm
20 The system cannot find the device specified.
雖然沒有多大意義
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.