如何在c++中使用system()来运行包含空格的python脚本
How to use system() in c++ to run python script containing space
我希望在c++代码中运行python脚本,但地址路径包含空格
以下是我要做的:
string python = ""D:\my folder\python.exe"";
string script = ""D:\my scripts\hello.py"";
string arg = ""argument 1"";
string cmd= python + " " + script + " " + arg;
system(cmd.c_str());
这里cmd""D:\my folder\python.exe" "D:\my scripts\hello.py"" ""argument 1""
,它是文本形式的,期望被执行为
"D: \my folder\python.exe"quot;D: \my scripts\hello.py"quot;自变量1";作为命令行,但执行失败,并出现错误->'D: "\my"未被识别为内部或外部命令。
但同样的命令";D: \my folder\python.exe"quot;D: \my scripts\hello.py"在命令提示符下工作正常吗
请在c++中建议如何执行路径中有空格的python脚本,并向脚本传递参数。
好吧,我找到了一种方法让它与系统((一起工作我试着和执行官谈过,但还是有一些问题。需要用双引号覆盖整个命令。
在我的情况下,它应该是"""D:\my folder\python.exe" "D:\my scripts\hello.py"" ""argument 1"""
相关文章:
- 如何在c++中使用system()来运行包含空格的python脚本
- 将包含二进制数据的 QByteArray 传递到按值运行
- 如果第一个元素包含任何零,则我的程序以不希望的方式运行
- 包含并运行来自其他文件的函数
- Visual C 运行时:Malloc将指针返回到已经使用的内存(包含实际字符串)
- 崇高文本 3 - 在终端中编译并运行 C++ 程序(路径包含空格)
- 移动包含正在运行的 std::thread 成员的对象
- 如何在 Linux 上将所有第三方运行时依赖项包含在 cmake/cpack 生成的包中
- 寻找一种在运行时检测 valgrind/memcheck 的方法,而无需包含 valgrind 标头
- C++ 当您需要包含OpenGL库时,如何在Clion中运行程序
- 运行C 程序,其中包含Fedora中的POSIX API
- 只有当输入文件确实包含要读取的另一个值时,我才能让getline(variable,n)运行
- C 在运行时评估包含文件
- Eclipse 在检查语法时看不到包含文件,但在构建或运行应用程序时会看到
- Python 可以运行脚本的多个实例,每个实例都包含自己的数据吗?
- 如何检查(在运行时)用户是否包含文件
- 获取<whatever>包含正在运行的可执行文件的 USB 驱动器C++ /dev/
- 包含boost::asio标头时引发运行时异常
- 需要包含运行任务时间的 2D 矩阵的最佳解决方案
- PIN工具是否可以插入一个bash脚本,其中包含运行其他命令的代码