[英]c++ Start process with argument
i know how to Start process with argument but im trying to create a program that uses this arguments. 我知道如何使用参数启动进程,但是我试图创建一个使用此参数的程序。 for example IE8 uses Process::Start( "IExplore.exe","google.com"); 例如IE8使用Process :: Start(“ IExplore.exe”,“ google.com”); as a argument to open new window with url google.com. 作为使用google.com网址打开新窗口的参数。 i want my program to use the argument are send it but i don't know how to get the the argument. 我希望我的程序使用自变量发送,但我不知道如何获取自变量。 like Process::Start( "myprogram.exe","TURE"); 像Process :: Start(“ myprogram.exe”,“ TURE”); i want my program to get the ture thanks in advance Rami 我希望我的程序提前致谢拉米
There are two choices, depending on what kind of program you are building. 有两种选择,具体取决于您要构建哪种程序。
argc
and argv
parameters passed to your main()
. 如果您的程序是控制台模式程序,请使用传递给main()
argc
和argv
参数。 pCmdLine
parameter passed to your WinMain()
. 如果您的程序是GUI模式程序,请使用传递给WinMain()
的pCmdLine
参数。 In either case, you can always use GetCommandLine()
. 无论哪种情况,您都可以始终使用GetCommandLine()
。
Assuming you write your entry point something like this: 假设您编写入口点,如下所示:
int main(int argc, char* argv[])
Then argc
is the number of arguments used to invoke your program and argv
are the actual arguments. 然后argc
是用于调用程序的参数数量,而argv
是实际参数。
Try it out: 试试看:
#include <cstdio>
int main(int argc, char* argv[])
{
for (int i = 0; i < argc; ++i)
printf("%s\n", argv[i]);
}
#include <stdlib.h>
...
system("IExplore.exe google.com");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.