Javascript Node.js,g++;(gcc)和子进程-gcc无法打开输出文件错误
对于编程竞赛,我正在制作一个简单的HTML/Javascript页面,用于获取您的源代码、编译和评估它们。这是我运行GCC的代码:Javascript Node.js,g++;(gcc)和子进程-gcc无法打开输出文件错误,javascript,c++,node.js,gcc,Javascript,C++,Node.js,Gcc,对于编程竞赛,我正在制作一个简单的HTML/Javascript页面,用于获取您的源代码、编译和评估它们。这是我运行GCC的代码: request.onfiles = function(files) { // Add output file name at the end of params files.push("-o output/main.exe"); // Evaluate correct working path, that's /upload/username
request.onfiles = function(files) {
// Add output file name at the end of params
files.push("-o output/main.exe");
// Evaluate correct working path, that's /upload/username
var cwd = path.resolve(process.cwd(), './upload/'+request.name+"/");
console.log(">> "+cwd+"/g++ ", files.join(" "));
console.log(process.cwd());
// Run process
var gcc = request.process = childProcess.spawn('g++',files,{env: process.env, cwd: cwd});
gcc.stdout.on('data', function (data) {
console.log('stdout: ' + data);
});
// Error output
gcc.stderr.on('data', function (data) {
console.log('stderr: ' + data);
});
gcc.on('close', function (code) {
console.log('child process exited with code ' + code);
_this.working.splice(_this.working.indexOf(request));
_this.emit("action.compile", request.name);
_this.tryContinue();
});
}
Node.js进程在项目根目录下运行,GCC在/upload/[USERNAME]/
中启动。/upload/username
目录包含源代码:
我的调试输出如下所示:
Compile by username requested.
>> D:\web\soutez\upload\username/g++ main.cpp -o output\main.exe
D:\web\soutez
stderr: c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin
stderr: /ld.exe: cannot open output file output\main.exe: No such file or directory
stderr:
collect2.exe: error: ld returned 1 exit status
child process exited with code 1
>> D:\web\soutez\upload\username/g++ main.cpp -o output\main.exe
D:\web\soutez
stderr: main.cpp:2:2: error: 'XXX' does not name a type
XXX
^
child process exited with code 1
如果我用命令(g++main.cpp-o output\main.exe
)复制该行,并进入upload/username
,编译工作:
我还注意到,尽管GCC总能找到源代码。如果在main.cpp
中添加错误,node.js输出如下:
Compile by username requested.
>> D:\web\soutez\upload\username/g++ main.cpp -o output\main.exe
D:\web\soutez
stderr: c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin
stderr: /ld.exe: cannot open output file output\main.exe: No such file or directory
stderr:
collect2.exe: error: ld returned 1 exit status
child process exited with code 1
>> D:\web\soutez\upload\username/g++ main.cpp -o output\main.exe
D:\web\soutez
stderr: main.cpp:2:2: error: 'XXX' does not name a type
XXX
^
child process exited with code 1
我需要一些帮助,我不明白node.js有什么不同。最糟糕的事情:如果我删除/output
,它会工作:
files.push("-o main.exe");
问题出在
-o output/main.exe
中。它应该是-ooutput/main.exe
。我发现这是因为它使用了-o main.exe
,过了一会儿,我注意到结果文件名的开头有一个
(空格)。问题在于-o output/main.exe
。它应该是-ooutput/main.exe
。我发现这是因为它使用了-o main.exe
,过了一会儿,我注意到在生成的文件名的开头有一个
(空格)。你确定生成的文件具有正确的权限吗?我在windows上,我关闭了UAC。所以每个人都是管理员。还请注意,错误是没有这样的文件或目录,而不是权限被拒绝。我完全迷路了——首先我还以为这是许可。很抱歉把你弄糊涂了。有没有可能是反斜杠造成了大破坏(在output\main.exe中)?没有,我尝试了正向和反向变量。甚至混合斜杠也不会对源路径造成任何问题。。/main.exe:没有这样的文件或目录
也不起作用,这真的很奇怪。看起来它拒绝在不同的目录中创建输出您确定生成的文件具有正确的权限吗?我在windows上,UAC处于关闭状态。所以每个人都是管理员。还请注意,错误是没有这样的文件或目录,而不是权限被拒绝。我完全迷路了——首先我还以为这是许可。很抱歉把你弄糊涂了。有没有可能是反斜杠造成了大破坏(在output\main.exe中)?没有,我尝试了正向和反向变量。甚至混合斜杠也不会对源路径造成任何问题。。/main.exe:没有这样的文件或目录
也不起作用,这真的很奇怪。看起来它拒绝在不同的目录中创建输出