0
我寫了下面的代碼來創建在運行腳本的cygwin的過程CreateProcess的不繼承父ENV
DWORD RunSilent(char* strFunct, char* strstrParams)
{
STARTUPINFO StartupInfo;
PROCESS_INFORMATION ProcessInfo;
char Args[4096];
char *pEnvCMD = NULL;
char *pDefaultCMD = "CMD.EXE";
ULONG rc;
memset(&StartupInfo, 0, sizeof(StartupInfo));
StartupInfo.cb = sizeof(STARTUPINFO);
StartupInfo.dwFlags = STARTF_USESHOWWINDOW;
StartupInfo.wShowWindow = SW_HIDE;
Args[0] = 0;
strcat(Args, strFunct);
strcat(Args, " ");
strcat(Args, strstrParams);
if (!CreateProcess(NULL, Args, NULL, NULL, TRUE,
/*CREATE_NEW_CONSOLE, */
0,
NULL,
NULL,
&StartupInfo,
&ProcessInfo))
{
return GetLastError();
}
WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
if(!GetExitCodeProcess(ProcessInfo.hProcess, &rc))
rc = 0;
CloseHandle(ProcessInfo.hThread);
CloseHandle(ProcessInfo.hProcess);
return rc;
}
int main(){
RunSilent("c:/cygwin64/bin/bash.exe", " --login -i -c \"/cygdrive/c/FP/V7/myscript \"");
return 0;
}
的MyScript的內容是:
if test $MY_HOME
then
FORMALHOME_HOME=$MY_HOME
export FORMALHOME_HOME
else
echo "A Home variable is required: missing \$MY_HOME"
exit -1
fi
運行我的程序它始終返回消息「需要一個主變量:缺少$ MY_HOME」 雖然變量$ MY_HOME已設置
似乎創建的進程不會繼承父母的環境
任何想法解決這個?
我刪除了它,但問題仍然存在 –