1. Invoke-Expression 'C:\setup.exe -url="http://mywebsite.com"' | Out-Null
2. Invoke-Expression 'C:\Tools\delcert.exe "c:\setup.exe"'
正如您在第1行所见,我正在更新我的setup.exe,这是成功的。在第二行,我从delcert.exe
收到错误,我认为这是因为第1行中的setup.exe尚未完全处理。
Out-Null
应该等到文件关闭并且不再有任何引用吗? 如果我注释掉第1行,那么第二行就会成功。此外,如果我在单独的cmd窗口中运行这两个命令,我不会遇到任何问题。想法?
在delcert.exe
内,这是它失败的代码(为了给你实际问题的背景)。
_tprintf(_TEXT("Stripping file: %s.\n"), pszFileName);
hFile = CreateFile(pszFileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, 0, NULL);
if (INVALID_HANDLE_VALUE == hFile) {
dwResult = GetLastError();
_tprintf(_TEXT("CreateFile failed with error 0x%08x\n"), dwResult);
goto cleanupAndExit;
}
答案 0 :(得分:2)
听起来像是时间问题。 Setup.exe可能异步运行。
使用start-process
代替:
Start-Process c:\Setup.exe -argumentlist '-url=http://mywebsite.com' -wait
在调用delcert之前,等待设置完成。