[英]Simple bash commands fails, cannot execute binary file
我嘗試在節點bu中執行一些簡單的bash報錯: /usr/bin/file: /usr/bin/file: cannot execute binary file
'use strict';
var spawn = require('child_process').spawn;
var process = spawn('bash', ['file']);
process.stdout.on('data', function(data){
console.log(data.toString());
});
process.stderr.on('data', function(data){
console.log(data.toString());
});
我什至給了腳本chmod + x並使用node script.js運行它
有任何想法嗎?
看起來在生成子進程時,您實際上是在嘗試運行“文件”命令,而不是Shell腳本,因此bash令您煩惱。
等同於在命令行上鍵入以下內容:“ bash文件”。
您將要編寫一個shell腳本並將其作為參數傳遞給bash進程。
因此,編寫一個名為“ do_something.sh”的腳本,然后使用['do_something.sh']作為bash而不是['file']的參數運行代碼:
var process = spawn('bash', ['do_something.sh']);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.