使用包含给定空格的路径启动程序
Start a program with a path containing spaces given
我有一个命令的字符串,例如: 开始C:Users...test application.exe
具有空格的路径。
现在我想使用system()
函数来启动它:
system(command.c_str());
但问题是,它没有启动,因为路径包含一个空格。 我该怎么做才能解决这个问题?
我该怎么做才能解决这个问题?
你需要知道的第一件事是system()
使用 shell 来执行命令,如果路径包含空格,shell 希望你用""
将程序路径括起来。
使用当前的C++标准,最简单的修复方法是使用原始字符串文字:
std::string command = R"("C:Userstest application.exe")";
system(command.c_str());
否则(对于较旧的C++标准),您需要转义所有特殊字符:
std::string command = "("C:\Users\test application.exe")";
// ^ ^ ^ ^
相关文章:
- 如何创建一个空的全局类并在启动时实例化它
- 如何将更多文件夹添加到c++include路径
- 带有特殊路径部分的"std::filesystem::weakly_canonical"失败
- C++A*算法并不总是在路径中具有目标节点
- 从函数角度看ID到文件路径的内部与外部映射
- 即使我读取了所有内容,在FIFO上打开的QSocketNotifier也会一直启动
- boost xml parsingl将xml的路径作为变量发送
- 使用 std::string () const 函数启动线程或未来
- 对于MacOS上的G++,如何添加默认的include目录/usr/local/include和默认的库搜索路径/usr
- 如何使用cppcheck处理半相对包含路径
- 在C++中设置基于操作系统的文件路径
- 基于编译器选项的编译二进制路径
- 从另一个应用启动我的应用时出现相对路径更改问题
- 使用包含给定空格的路径启动程序
- VS 代码C++:无法启动调试 - 程序路径丢失或无效
- Eclipse在退出和/或启动(CDT)时编辑我的包含路径
- 当路径中有空格时,从与Qt应用程序相同的目录启动可执行文件
- QtCreator:启动程序失败.路径或权限错误
- CMD.EXE以上述路径作为当前目录启动.不支持UNC路径.默认为“Windows目录”
- 在参数列表中使用绝对路径启动QProcess