更改系统命令参数的路径

编程入门 行业动态 更新时间:2024-10-10 21:26:27
本文介绍了更改系统命令参数的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我有一个 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-27 15:13:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1157045.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路径   命令   参数   系统

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!