Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/145.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
W8注册问题?从C++;应用程序,但未传递任何参数 我有一个C++程序,它使用 Stand()/Cux>调用来执行并发送参数到shell脚本。它在我的Windows 8.1计算机上运行良好。现在我正试图在一台新的Windows8.1笔记本电脑上运行同样的东西。执行shell脚本,但未收到任何参数 #!/bin/bash echo "received arguments: $# " C++代码< /p> system(("C:/script.sh file.png &").c_str());_C++_Bash_Shell_Arguments_Registry - Fatal编程技术网 system(("C:/script.sh file.png &").c_str());,c++,bash,shell,arguments,registry,C++,Bash,Shell,Arguments,Registry" /> system(("C:/script.sh file.png &").c_str());,c++,bash,shell,arguments,registry,C++,Bash,Shell,Arguments,Registry" />

W8注册问题?从C++;应用程序,但未传递任何参数 我有一个C++程序,它使用 Stand()/Cux>调用来执行并发送参数到shell脚本。它在我的Windows 8.1计算机上运行良好。现在我正试图在一台新的Windows8.1笔记本电脑上运行同样的东西。执行shell脚本,但未收到任何参数 #!/bin/bash echo "received arguments: $# " C++代码< /p> system(("C:/script.sh file.png &").c_str());

W8注册问题?从C++;应用程序,但未传递任何参数 我有一个C++程序,它使用 Stand()/Cux>调用来执行并发送参数到shell脚本。它在我的Windows 8.1计算机上运行良好。现在我正试图在一台新的Windows8.1笔记本电脑上运行同样的东西。执行shell脚本,但未收到任何参数 #!/bin/bash echo "received arguments: $# " C++代码< /p> system(("C:/script.sh file.png &").c_str());,c++,bash,shell,arguments,registry,C++,Bash,Shell,Arguments,Registry,在shell脚本中,我验证收到的参数数量 #!/bin/bash echo "received arguments: $# " 我可以从Git Bash手动执行并向脚本传递参数 $ sh script.sh file.png received arguments: 1 但如果我在C++中使用 Sype()/Cudio>调用,接收到的参数总是0。同样的精确代码在另一台机器上运行良好。问题似乎与Windows注册表有关。我第一次在新的笔记本上运行C++程序时,Windows问我应该用什么程序

在shell脚本中,我验证收到的参数数量

#!/bin/bash
echo "received arguments:  $# "
我可以从Git Bash手动执行并向脚本传递参数

$ sh script.sh file.png 
received arguments: 1

但如果我在C++中使用<代码> Sype()/Cudio>调用,接收到的参数总是0。同样的精确代码在另一台机器上运行良好。问题似乎与Windows注册表有关。我第一次在新的笔记本上运行C++程序时,Windows问我应该用什么程序来执行shell脚本。我选择了PowerShell。然而,这只会导致PowerShell疯狂地打开/关闭,我不得不重新启动计算机。然后我转到explorer并将要打开的.sh与Git Bash关联起来。现在从C++程序中执行脚本,安全地传递参数。 我的注册表设置是否可能以某种方式禁止数据传递


考虑调用
系统(“/path/to/bash C:/script.sh file.png&”)来简化操作系统的操作,否则操作系统需要启动shebang中建议的程序。

系统()
可能不是合适的工具。相反,你应该去调查一下。它省去了很多猜测。thx@IInspectable-目前
system()
确实有效,所以我会坚持使用它。但肯定会考虑下一次你的建议。现在系统必须猜测位置。同时,向前斜杠会让你的生活变得更轻松。窗口上的路径分隔符是反斜杠。只要您转义反斜杠,它就会编译,例如:
C:\\script.sh
@IInspectable:奇怪,为了在Cygwin:
int I=system(“bash C:\\\\script.sh file.png”)中成功编译和运行,我必须使用4个反斜杠。无论如何,OP的问题是将脚本传递给正确的程序,我相信这至少是一个很好的解决方法。是的!非常感谢。只要
system(“bash C:/script.sh file.png&”)就可以了