我正在尝试使用child_process.spawn
和msdeploy.exe自动部署IIS中的某些应用程序。
每当我的dest站点名称中有空格时,这会导致msdeploy崩溃。
var command = 'C:/Program Files/IIS/Microsoft Web Deploy V3/msdeploy.exe';
var args = [];
args.push('-verb=sync');
args.push('-source:iisApp=C:/Users/PATH_TO_DEPLOY/dist');
args.push('-dest:iisApp=Default Web Site/test');
var process = spawn(command,args);
process.stdout.on('data', function(data) { grunt.log.write(data) });
process.stderr.on('data', function(data) { grunt.log.error(data); });
process.on('exit', function(code) {
if (code !== 0) {
grunt.fail.warn('Something went wrong');
}
done();
});
我尝试了其他一些替代方案,例如put" '-dest:iisApp="Default Web Site/test"'
但msdeploy也给我一个错误。
此错误类似于:Argument '"-dest:iisApp=Default Web Site/haha"' not recognized. All arguments must begin with "-" char
。
当我试图逃离空间字符或放置"如上所述,这给了我一个类似的错误。
这是nodejs中的错误吗?也许我做错了什么? 感谢。
答案 0 :(得分:0)
如何做到这一点:
var path = require('path');
var platform = require('platform');
var cp = require('child_process');
var full_cmd = '/path/to/dir with space/program.exe';
var cmd = '.' + path.sep + path.basename(full_cmd); // cannot include double quotes -- the work-around is to use the 'cmd_opts.cwd'
var cmd_args = ['"--import-path=/path/to/dir with space/import_file"']; // can wrap each with double-quotes (Windows only -- fails on Unix)
var cmd_opts = {
cwd: path.dirname(full_cmd),
encoding: 'utf8'
};
if (platform.os() === 'win32') {
cmd_opts.windowsVerbatimArguments = true;
}
var proc = cp.spawn(
cmd,
cmd_args,
cmd_opts
);
唯一不起作用的方法是将'program.exe'命名为'program name with space.exe'