how to call vcvarsall.bat with Process::Start method?
-
I try to invoke oracle pro*c in C++/CLI project. This is my sample code. #include "stdafx.h" using namespace System; using namespace System::IO; using namespace System::Diagnostics; void call_Process (ProcessStartInfo^ info) { try { Process^ exeP = Process::Start(info); StreamReader^ reader = exeP->StandardOutput; String^ result = reader->ReadToEnd(); Console::Write(result); Console::ReadLine(); } catch(Exception^ e) { Console::WriteLine(e->Message); Console::ReadLine(); } } int main(array ^args) { ProcessStartInfo^ pStartInfo = gcnew ProcessStartInfo(); pStartInfo->UseShellExecute = false; pStartInfo->RedirectStandardOutput = true; pStartInfo->WindowStyle = ProcessWindowStyle::Hidden; pStartInfo->FileName = "\"C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\vcvarsall.bat\""; pStartInfo->Arguments = "x64"; call_Process(pStartInfo); pStartInfo->FileName = "proc.exe"; pStartInfo->Arguments = "oracle_connect.pc"; call_Process(pStartInfo); pStartInfo->FileName = "\"C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\bin\\amd64\\cl.exe\""; String^ arg1 = " /I C:\\app\\Administrator\\product\\11.2.0\\dbhome_1\\precomp\\public"; String^ arg2 = " /link C:\\app\\Administrator\\product\\11.2.0\\dbhome_1\\precomp\\LIB\\ORASQL11.LIB"; pStartInfo->Arguments = arg1 + " oracle_connect.c" + arg2; call_Process(pStartInfo); // throws exception. pStartInfo->FileName = "oracle_connect.exe"; call_Process(pStartInfo); return 0; } When I type in ,call vcvarsall.bat in command prompt window myself and run this codes, it works. No exception. But when I run this code in another command prompt window without calling vcvarsall.bat, it throws exception. Calling vcvarsall.bat with Process::Start method doesn't work! Pls, advise me how to call vcvarsall.bat with Process::Start method. Thanks in advance. Best Regards!
Joseph Hwang
-
I try to invoke oracle pro*c in C++/CLI project. This is my sample code. #include "stdafx.h" using namespace System; using namespace System::IO; using namespace System::Diagnostics; void call_Process (ProcessStartInfo^ info) { try { Process^ exeP = Process::Start(info); StreamReader^ reader = exeP->StandardOutput; String^ result = reader->ReadToEnd(); Console::Write(result); Console::ReadLine(); } catch(Exception^ e) { Console::WriteLine(e->Message); Console::ReadLine(); } } int main(array ^args) { ProcessStartInfo^ pStartInfo = gcnew ProcessStartInfo(); pStartInfo->UseShellExecute = false; pStartInfo->RedirectStandardOutput = true; pStartInfo->WindowStyle = ProcessWindowStyle::Hidden; pStartInfo->FileName = "\"C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\vcvarsall.bat\""; pStartInfo->Arguments = "x64"; call_Process(pStartInfo); pStartInfo->FileName = "proc.exe"; pStartInfo->Arguments = "oracle_connect.pc"; call_Process(pStartInfo); pStartInfo->FileName = "\"C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\bin\\amd64\\cl.exe\""; String^ arg1 = " /I C:\\app\\Administrator\\product\\11.2.0\\dbhome_1\\precomp\\public"; String^ arg2 = " /link C:\\app\\Administrator\\product\\11.2.0\\dbhome_1\\precomp\\LIB\\ORASQL11.LIB"; pStartInfo->Arguments = arg1 + " oracle_connect.c" + arg2; call_Process(pStartInfo); // throws exception. pStartInfo->FileName = "oracle_connect.exe"; call_Process(pStartInfo); return 0; } When I type in ,call vcvarsall.bat in command prompt window myself and run this codes, it works. No exception. But when I run this code in another command prompt window without calling vcvarsall.bat, it throws exception. Calling vcvarsall.bat with Process::Start method doesn't work! Pls, advise me how to call vcvarsall.bat with Process::Start method. Thanks in advance. Best Regards!
Joseph Hwang
-
I try to invoke oracle pro*c in C++/CLI project. This is my sample code. #include "stdafx.h" using namespace System; using namespace System::IO; using namespace System::Diagnostics; void call_Process (ProcessStartInfo^ info) { try { Process^ exeP = Process::Start(info); StreamReader^ reader = exeP->StandardOutput; String^ result = reader->ReadToEnd(); Console::Write(result); Console::ReadLine(); } catch(Exception^ e) { Console::WriteLine(e->Message); Console::ReadLine(); } } int main(array ^args) { ProcessStartInfo^ pStartInfo = gcnew ProcessStartInfo(); pStartInfo->UseShellExecute = false; pStartInfo->RedirectStandardOutput = true; pStartInfo->WindowStyle = ProcessWindowStyle::Hidden; pStartInfo->FileName = "\"C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\vcvarsall.bat\""; pStartInfo->Arguments = "x64"; call_Process(pStartInfo); pStartInfo->FileName = "proc.exe"; pStartInfo->Arguments = "oracle_connect.pc"; call_Process(pStartInfo); pStartInfo->FileName = "\"C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\bin\\amd64\\cl.exe\""; String^ arg1 = " /I C:\\app\\Administrator\\product\\11.2.0\\dbhome_1\\precomp\\public"; String^ arg2 = " /link C:\\app\\Administrator\\product\\11.2.0\\dbhome_1\\precomp\\LIB\\ORASQL11.LIB"; pStartInfo->Arguments = arg1 + " oracle_connect.c" + arg2; call_Process(pStartInfo); // throws exception. pStartInfo->FileName = "oracle_connect.exe"; call_Process(pStartInfo); return 0; } When I type in ,call vcvarsall.bat in command prompt window myself and run this codes, it works. No exception. But when I run this code in another command prompt window without calling vcvarsall.bat, it throws exception. Calling vcvarsall.bat with Process::Start method doesn't work! Pls, advise me how to call vcvarsall.bat with Process::Start method. Thanks in advance. Best Regards!
Joseph Hwang
You cannot execute these processes independently in this way.
vcvarsall.bat
needs to be called in the same environment that the compiler will be called. You need to create a new batch file that contains all the commands that you wish to run, and execute that batch file.Use the best guess