C++使用system()启动程序时没有得到所需的结果
C++ Launching programs with system() not giving desired results
我有一个C++代码设置,它为我启动项目,我所要做的就是输入名称并启动。问题是,当我让C++应用程序启动它时,C++应用程序"变成了它"。我的意思是假装我正在使用它启动minecraft服务器。它会像minecraft服务器一样,不使用目录中的文件。如果有人能帮忙,请帮忙。
(这是代码)
#include <iostream>
#include <stdlib.h>
#include <string>
using namespace std;
int main() {
std::string textin;
cin >> textin;
if ( textin == "ATLauncher" ) {
system("C:\users\USER\Main\minecraftserver\minecraftserver.exe");
return 0;
}
}
听起来你想在启动之前更改工作目录。在posix中工作,您想要的呼叫是chdir(path)
。在系统调用之前进行该调用。
请注意,Windows将工作目录存储在其他位置(在快捷链接中),因此您可能需要查看该目录以确定正确的路径。
相关文章:
- 为什么"do while"循环不断退出,即使条件计算结果为 false?
- valgrind-hellgrind与泄漏检查的结果不同
- 用C++20 fmt限制结果的总大小
- 如何返回一个类的两个对象相加的结果
- 使用QProcess执行命令,并将结果存储在QStringList中
- 如果我std::dynamic_pointer_cast并且底层dynamic_cast的结果为null,那么返回的sh
- 在没有定义返回类型的函数中返回布尔值,并将结果保存在无错误的char编译中-为什么
- 序列化,没有库的整数,得到奇怪的结果
- 使用取消引用的指针的多态性会产生意外的结果.为什么?
- 在更改for循环的第三部分后,未使用for循环结果
- 使用++运算符会导致意外的结果
- 如何在c++中使用system()来运行包含空格的python脚本
- 为什么在逗号分隔符上下文中将预增量的结果强制转换为void
- C++Brute Force攻击函数不会返回结果
- System.InvalidCastException - SQL to C++ - safe_cast<float>
- 你好。。。id_public变量不应该给出结果为 81 和 86 吗?为什么它为两个派生类占用不同的内存位置?
- 从 C 代码 system() 函数执行的 Linux 命令与从终端执行时给出的结果不同
- C++使用system()启动程序时没有得到所需的结果
- 在程序中操作"system"调用的结果C++
- 终端命令和 c++ system(..) 命令返回不同的结果