2015-07-21 148 views
0

有人可以幫助我找到使用java腳本執行批處理文件的解決方案,我目前正在使用nw.js,並且我嘗試了幾個適用於.exe的東西,但沒有對於蝙蝠使用Java腳本執行.bat文件

var execFile = require 
('child_process').execFile, child; 
child = execFile('C:\\WorkLog\\Software\\abc.exe', //works 
//child = execFile('C:\\PDFRotation\\Run.bat', //not working 
+0

看起來像node.js – npocmaka

+0

@npocmaka nw.js是一個JS庫,用於從DOM調用節點模塊。 –

回答

2

批處理程序是不是一個真正的可執行文件,所以你可能需要使用cmd.exe來調用批處理文件,你可以試試:

var spawn = require('child-process').spawn; 

spawn('cmd.exe', ['yourfile.bat']); 
+0

我嘗試了這樣的東西,但這是行不通的: - var spawn = require('child_process')。spawn,child; child = spawn('cmd.exe',['C:\\ PDFRotation \\ Run.bat']); child.stderr.setEncoding('utf8'); ('data',function(data){0} {0}}如果(/^execvp(())..((data)){ console.log('無法啓動子進程。'); } }); – karan

+0

你得到了什麼錯誤 –

1

其實你不執行批處理文件。您執行cmd.exe並將批處理文件作爲參數提供給它。