admin管理员组文章数量:1291285
var exec = require('child_process').exec
var cmd = 'C:\\Users\\Johnny Cash\\Desktop\\executeme.exe'
exec(cmd, function(e, stdout, stderr) {
console.log(e);
console.log(stdout);
console.log(stderr);
});
'C:\Users\Johnny' is not recognized as an internal or external mand
This has got to be the newbiest question ever, but how do I escape these paths with spaces on windows? It's cuts off at the space and nothing I do (single or double escapes beforehand) seems to do the trick. Does exec()
do some formatting I'm not aware of?
var exec = require('child_process').exec
var cmd = 'C:\\Users\\Johnny Cash\\Desktop\\executeme.exe'
exec(cmd, function(e, stdout, stderr) {
console.log(e);
console.log(stdout);
console.log(stderr);
});
'C:\Users\Johnny' is not recognized as an internal or external mand
This has got to be the newbiest question ever, but how do I escape these paths with spaces on windows? It's cuts off at the space and nothing I do (single or double escapes beforehand) seems to do the trick. Does exec()
do some formatting I'm not aware of?
2 Answers
Reset to default 10exec
treats any spaces in the mand
parameter string as argument separators, so you need to double-quote the whole path to have it all treated as the path to the mand to run:
var cmd = '"C:\\Users\\Johnny Cash\\Desktop\\executeme.exe"'
But it's probably cleaner just to use execFile
instead, as its file
parameter is always treated as the file path, with a separate args
parameter. Then you should be able to omit the double-quote wrapping. execFile
is a bit leaner anyway as it doesn't execute a subshell like exec
does.
You need to scape the space char from the URI by using ^
(caret) char:
var cmd = 'C:\\Users\\Johnny^ Cash\\Desktop\\executeme.exe'
本文标签: javascriptnode39s exec() not working because of a space in the URI nameStack Overflow
版权声明:本文标题:javascript - node's exec() not working because of a space in the URI name - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741529373a2383662.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论