Gulp 任务 child_process.spawn curl 错误

Gulp task child_process.spawn curl error

我正在编写一个 Gulp 任务,它将执行 curl 请求以将文件上传到 API。

这是从命令行按预期执行的请求:

curl \
  -F "files[strings.pot]=@/path/to/file/i18n/strings.pot" \
  -F "json=true" \
  https://api.crowdin.com/api/project/xxxxxx/update-file?key=yyyyyy

这是我目前写的任务:

var args = [];
args.push('-F "files[strings.pot]=@/path/to/file/i18n/strings.pot"')
args.push('-F "json=true"');
args.push('https://api.crowdin.com/api/project/'+meta.crowdin.projectIdentifier+'/update-file?key='+meta.crowdin.projectKey);

cp.spawn('curl', args, { stdio: 'inherit' })
 .on('close', function(){
    bundleLogger.end("Crowdin - Did upload POT in");
 })
 .on('exit', function(code){
    console.log('Exit code: '+code);
 });

这个returnscurl: (26) couldn't open file "/path/to/file/i18n/strings.pot".

child_process 是否使用不同的权限或 $PATH 或其他会导致此错误的内容生成?

我已经解决了这个问题。

"files[strings.pot]..." 周围的双引号被视为文件名的一部分。这有效:

var args = [];
args.push('-F files[strings.pot]=@/path/to/file/i18n/strings.pot');
args.push('-F json=true');
args.push('https://api.crowdin.com/api/project/'+meta.crowdin.projectIdentifier+'/update-file?key='+meta.crowdin.projectKey);

cp.spawn('curl', args, { stdio: 'inherit' })
 .on('close', function(){
    bundleLogger.end("Crowdin - Did upload POT in");
 })
 .on('exit', function(code){
    console.log('Exit code: '+code);
 });