【发布时间】:2019-12-04 10:53:34
【问题描述】:
我正在开发一个在 Windows 上使用 CodeBlocks 的 C++ 项目,但后来决定切换到 NetBeans IDE 8.2。
在我的项目中,我正在调用另一个带有一些传递参数的可执行文件(我使用合适的参数运行另一个 .exe,然后我将它的输出用于我的主项目),它曾经在 CodeBlocks 上工作,但是不在 NetBeans 上。
代码如下:
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <cstdlib>
#include <string.h>
#include <sstream>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include "My_Constants.h"
#include "Data.h"
#include "Parameters.h"
#include "Pattern.h"
#include "Squish.h"
#include "Deserializer.h"
#include "Automatic_Run.h"
using namespace std;
int main()
{
Parameters parameters;
parameters.mode = SQUISH;
Automatic_Run runner;
string inputname;
//--------------------------------User Input-------------------------------------
cout << "enter input file name \n";
getline(cin, inputname);
parameters.inputFileName.assign(inputname);
cout<<"=============================================================================\n";
//--------------------------------Running SQUISH/first call--------------------------
cout<<"Running SQUISH - first call\n";
char command[1000]="";
string passedParameters = " -i "+parameters.inputFileName +" -f "+ "t";
strcat(command,"C:\\Users\\Administrator\\Documents\\CodeBlocksProjects\\TestSQUISH\\bin\\Debug\\TestSQUISH.exe ");
strcat(command,passedParameters.c_str());
int result = system(command);
// the rest of the code(not relevant to the problem)
return 0;
}
在 CodeBlocks 上,它曾经完美地工作,并在我的主项目(我从中调用 TestSQUISH 的那个)路径中将输出作为文件提供给我。但是,现在在 NetBeans 上,我收到以下错误:
sh: C:UsersAdministratorDocumentsCodeBlocksProjectsTestSQUISHbinDebugTestSQUISH.exe: 找不到命令
我检查了 NetBeans 的终端以了解正在发生的事情(假设它可能相关),我注意到我必须先更改路径,然后使用以下命令运行可执行文件:
./TestSQUISH.exe (+参数)
但是,这也不适用于我的项目。
谁能提出解决方案或告诉我如何让 NetBeans 像 CodeBlocks 过去那样在 Windows 终端上运行命令?
【问题讨论】:
-
那不是合法的 C++。请提供您正在编译和执行的确切代码。
-
我猜你需要 4x\ 而不是 2x\
-
谢谢,我试过了,它解决了“/”问题,但是找不到命令的主要问题仍然存在:sh: C:\Users\Administrator\Documents\CodeBlocksProjects\TestSQUISH\bin \Debug\TestSQUISH.exe:找不到命令@JVApen
-
目录的完整路径是否存在?可执行文件是否存在?
-
从错误消息看来,NetBeans 使用了
shshell(不知何故)。你确定它理解以C:开头的Windows风格的路径吗?
标签: c++ netbeans system codeblocks