c++ - C++“系统(命令)”在 NetBeans / Windows 上不起作用
问题描述
我正在使用 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 终端上运行命令?
解决方案
感谢@Yksisarvinen 的评论,我能够解决问题。
注意到 NetBeans 使用的是 shell 而不是 Windows 样式的命令,并且在使用 NetBeans 自己的终端真正清楚地了解它如何转换路径之后,我能够使用以下命令成功运行代码:
char command[1000]="";
string passedParameters = " -i "+parameters.inputFileName +" -f "+ "t";
strcat(command, "/cygdrive/c/Users/Administrator/Documents/CodeBlocksProjects/TestSQUISH/bin/Debug/TestSQUISH.exe ");
strcat(command,passedParameters.c_str());
int result = system(command);
Netbeans 终端添加cygdrive
到路径的开头,并c
使用C:
.
如果可执行文件与您自己的项目位于同一目录中,那么这就足够了:
char command[1000]="";
string passedParameters = " -i "+parameters.inputFileName +" -f "+ "t";
strcat(command ,"./TestSQUISH.exe ");
strcat(command,passedParameters.c_str());
int result = system(command);
推荐阅读
- julia - 在 julia 中将 Expr 转换为数组
- java - 提取body的属性,同时保留相对标签
- docker - 如何维护与 github 文件夹同步的 docker 容器
- bash - 如何在shell脚本中将文件从当前目录移动到另一个目录?
- kubernetes - kubectl rollout 重启部署
没有得到最新的图像 - sql - 如何将子查询中的唯一 ID 插入表中?
- node.js - 具有 JWT 身份验证 refresh_token 的系统如何横向扩展
- c++ - C 标准库中的符号是否保留在 C++ 中?
- c - mpi 相互发送和接收所有进程
- python - 如何转义字符串中的特殊字符(Python 3.7)