CreateProcess第一个参数可以用相对路径么?解决办法
CreateProcess第一个参数可以用相对路径么?
我用VC2005创建一个工程,里面两个vcproj,主工程的exe用来CreateProcess创建辅助工程的exe
在主工程里面我有
一个辅助工程用来生成sub.exe,里面就是一个空的main函数。
这两个工程编译之后,exe都在同一个debug目录下面。
但是我发现CreateProcess不成功,返回FALSE。我把第一个参数改为"..\\sub.exe"也不行,必须改成
"d:\\myproj\\debug\\sub.exe"这样的绝对路径,CreateProcess才能返回TRUE.
这是为什么呢? CreateProcess难道不能使用相对路径么? 还是我的用法有问题?
我的电脑-->属性-->高级里面的环境变量PATH已经包含了当前路径"." 但是还是不行啊。重起了几次IDE,一样的结果。
高手帮忙解释一下吧!
------解决方案--------------------
最好用绝对路径。
用GetModuleFileName()得到当前exe进程的路径,然后拼成你需要的路径即可。
------解决方案--------------------
可以用
在VS2005的工程属性里面把当前路径改成 $(TargetDir)
或者把程序拷贝到你cpp文件同一个目录下面去
或者直接运行你的程序,不通过VS调试
------解决方案--------------------
可以,至少当前目录以及当前目录的子目录都可以,这就叫相对了。
------解决方案--------------------
The string can specify the full path and file name of the module to execute or it can specify a partial name. In the case of a partial name, the function uses the current drive and current directory to complete the specification. The function will not use the search path. This parameter must include the file name extension; no default extension is assumed.
是支持相对路径的。但是not use the search path
你是不是在VC里面用ctrl + F5启动的啊,你直接运行EXE试试.
你用ctrl + f5它的运行路径是在工程目录不是你的debug目录
我用VC2005创建一个工程,里面两个vcproj,主工程的exe用来CreateProcess创建辅助工程的exe
在主工程里面我有
- C/C++ code
STARTUPINFO si={0}; PROCESS_INFORMATION pi={0}; BOOL hProc=CreateProcess("sub.exe", NULL,NULL,NULL,TRUE,NORMAL_PRIORITY_CLASS,NULL,NULL,&si,&pi);
一个辅助工程用来生成sub.exe,里面就是一个空的main函数。
这两个工程编译之后,exe都在同一个debug目录下面。
但是我发现CreateProcess不成功,返回FALSE。我把第一个参数改为"..\\sub.exe"也不行,必须改成
"d:\\myproj\\debug\\sub.exe"这样的绝对路径,CreateProcess才能返回TRUE.
这是为什么呢? CreateProcess难道不能使用相对路径么? 还是我的用法有问题?
我的电脑-->属性-->高级里面的环境变量PATH已经包含了当前路径"." 但是还是不行啊。重起了几次IDE,一样的结果。
高手帮忙解释一下吧!
------解决方案--------------------
最好用绝对路径。
用GetModuleFileName()得到当前exe进程的路径,然后拼成你需要的路径即可。
------解决方案--------------------
可以用
在VS2005的工程属性里面把当前路径改成 $(TargetDir)
或者把程序拷贝到你cpp文件同一个目录下面去
或者直接运行你的程序,不通过VS调试
------解决方案--------------------
可以,至少当前目录以及当前目录的子目录都可以,这就叫相对了。
------解决方案--------------------
The string can specify the full path and file name of the module to execute or it can specify a partial name. In the case of a partial name, the function uses the current drive and current directory to complete the specification. The function will not use the search path. This parameter must include the file name extension; no default extension is assumed.
是支持相对路径的。但是not use the search path
你是不是在VC里面用ctrl + F5启动的啊,你直接运行EXE试试.
你用ctrl + f5它的运行路径是在工程目录不是你的debug目录