更改系统命令参数的路径 [英] Change the path for system command parameters

查看:30
本文介绍了更改系统命令参数的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 C++ 项目,我为其生成了一个 .exe.

该程序有一些代码如下:

system(TestApplication.exe input.txt output.txt)系统(TestApplication1.exe input1.txt output1.txt)系统(TestApplication2.exe input2.txt output2.txt)

我实际上尝试将 .exe 保存在项目目录中的另一个文件夹中,即(EXE)和另一个文件夹中的文件(数据).

如果更改了exe的路径,它实际上找不到文件.我认为更改系统中的路径存在问题,因为它告诉 EXE 不是可识别的命令:

system("EXEs/TestApplication1.exe ....)

C++中系统命令的路径是如何改变的?

解决方案

假设你的项目目录设置为

<块引用>

set PROJECT_DIR = "C:\myproject\rundir"

你的可执行文件在项目目录中,它在文件夹中

<块引用>

C:\myproject\myexdir\

然后你可以做的是总是使用 PROJECT_DIR 来定位你的可执行文件

char myexe_dir[256];sprintf(myexe_dir,"%s\\..\\myexdir\\a.exe arg1 arg2",getenv("PROJECT_DIR"));系统(myexe_dir);

I have a C++ project for which I have generated an .exe.

The program has some code as following:

system(TestApplication.exe input.txt output.txt)
system(TestApplication1.exe input1.txt output1.txt)
system(TestApplication2.exe input2.txt output2.txt)

I actually tried keeping the .exe's inside another folder in the project directory i.e. (EXEs) and files in another one (Data).

It actually cannot find the files if the path for exe is changed. I think there's a problem in changing the path in system as since it tells that EXEs is not a recognized command:

system("EXEs/TestApplication1.exe .... )

How is the path changed for the system command in C++?

解决方案

Assume your Project directory is set as

set PROJECT_DIR = "C:\myproject\rundir"

and your executable is inside the project directory and it is inside the folder

C:\myproject\myexdir\

Then what you can do is always use the PROJECT_DIR to locate your executable like

char myexe_dir[256];
sprintf(myexe_dir,"%s\\..\\myexdir\\a.exe arg1 arg2",getenv("PROJECT_DIR"));
system(myexe_dir);

这篇关于更改系统命令参数的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆