如何在C中正确使用系统
我正在尝试与C一起打开Google的
。
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
system(" C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe ");
return 0;
}
Chrome 将“启动”放在Google文件路径的前面时。
今天,在取出“启动”并离开文件路径之后,我遇到了错误:
sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: ` C:\Program Files (x86)\Google\Chrome\Application\chrome.exe '
我替换了Google的文件路径:
system("notepad");
它使记事本没有问题。
我使用GCC编译,然后使用./a.exe运行可执行文件,
我完全丢失了 - 有建议吗?
注意 这是第一次在这里问一个问题,所以如果我错过了任何有价值的信息,请让我知道
I'm trying to open Google's Chrome with C.
I'm using Cygwin bash as my terminal and have added it to my PATH - here's my code:
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
system(" C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe ");
return 0;
}
Yesterday I had the problem of an error showing "sh: Start: Command not found" when putting "Start" in front of the google file path.
Today, after taking out the "Start" and just leaving the file path, I'm getting the errors:
sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: ` C:\Program Files (x86)\Google\Chrome\Application\chrome.exe '
I replaced the file path of google for:
system("notepad");
and it pulls up notepad no problem.
I compile using gcc then run the executable with ./a.exe
I'm completely lost - any advice?
NOTE
This is the first time asking a question here, so if I missed any valuable info please let me know
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
回想一下,默认情况下,空间是分隔线和分隔符,它们将命令行的不同部分划分。借助您的原始命令,您的命令行被解析为:
在其他单词中,它试图执行程序
c:\ program
,带有gragmentsfiles
和(x86) \ Google ....
。通过添加围绕它的引号,您正在告诉shell(在您的情况下,可能
cmd
)您是 不是 试图执行c :\ program
带有两个参数。相反,引号澄清您要执行
“ c:\ program Files(x86)\ google \ chrome \ chrome \ application \ chrome.exe”
作为可执行文件的一个重要路径,包括太空和名称中的帕伦斯(Parens)。Recall that spaces, by default, are delimiters and separators that divide different parts of the command line. With your original command, your command line was parsed as:
In otherwords, it was trying to execute program
C:\Program
, with argumentsFiles
and(x86)\Google....
.By adding quotes around it, you are telling the shell (likely
CMD
in your case) that you are not trying to executeC:\Program
with two arguments.Instead, the quotes clarify that you want to execute
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
as one big path to executable, including the spaces and parens within the name.摆脱后斜切,做一个
或
Get rid of the backslashes and do a
or a