473,385 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

C# .net system.diagnostics.process

rhitam30111985
112 100+
Hi all i am trying to compile a set of source files located in location In the following code sample i am trying to compile a visual c++ 6.0 (dsp) project from a c# application



Expand|Select|Wrap|Line Numbers
  1.  ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd", @"/c  set path=%programfiles%\Microsoft Visual Studio\Common\MSDev98\Bin");
  2.             procStartInfo.RedirectStandardOutput = true;
  3.             procStartInfo.UseShellExecute = false;
  4.             System.Diagnostics.Process proc = new System.Diagnostics.Process();
  5.             proc.StartInfo = procStartInfo;
  6.             proc.Start();
  7.  
  8.             proc.WaitForExit();
  9.  
  10.             procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd", @"/c  MSDEV C:\Shared\Source\Binaries\Project\Project.dsp /MAKE  /REBUILD >> compilerr.txt");
  11.             proc.StartInfo = procStartInfo;
  12.             procStartInfo.RedirectStandardOutput = true;
  13.             procStartInfo.UseShellExecute =false;
  14.  
  15.             proc.Start();
But for the first process(set path) it gives error :

'proc.ExitCode' threw an exception of type 'System.InvalidOperationException'

and for the msdev command :

'proc.BasePriority' threw an exception of type 'System.InvalidOperationException'


Any idea where i could be going wrong ?

Thanks a lot ,

Rhitam
Sep 12 '08 #1
7 15758
Plater
7,872 Expert 4TB
I don't think you can use the output operators >> << | inside the arguments of the process class can you?
The lines of code that threw the exceptions are not included in your sample source code?
Sep 12 '08 #2
rhitam30111985
112 100+
I don't think you can use the output operators >> << | inside the arguments of the process class can you?
The lines of code that threw the exceptions are not included in your sample source code?


While stepping through the code ... the IDE (Visual c# express) is not throwing any exception .. but if i mouse over the process variable (proc) ... and see its members .. then i get this exception ... it is thrown at each proc.start() line in the sample code ..

as for the output operators .. thats secondary. . i am not even able to execute the set path command ..
Sep 12 '08 #3
rhitam30111985
112 100+
I tried only the set path option like this :

Expand|Select|Wrap|Line Numbers
  1.  
  2.  System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(@"set path=%programfiles%\Microsoft Visual Studio\Common\MSDev98\Bin");
  3.             psi.UseShellExecute = false;
  4.             psi.RedirectStandardOutput = true;
  5.             psi.RedirectStandardInput = true;
  6.             psi.RedirectStandardError = true;
  7.             System.Diagnostics.Process proc = System.Diagnostics.Process.Start(psi);
  8.  
then it gives the error :

The system cannot find the file specified win32 exception was unhandled

stacktrace:


at System.Diagnostics.Process.StartWithCreateProcess( ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
at GetBuildSource.Program.Main(String[] args) in C:\Shared\Test Environment\GetBuildSource\Program.cs:line 39
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context( Object state)
at System.Threading.ExecutionContext.Run(ExecutionCon text executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Sep 12 '08 #4
Plater
7,872 Expert 4TB
While stepping through the code ... the IDE (Visual c# express) is not throwing any exception .. but if i mouse over the process variable (proc) ... and see its members .. then i get this exception ... it is thrown at each proc.start() line in the sample code ..

as for the output operators .. thats secondary. . i am not even able to execute the set path command ..
Haha, yeah of course they will. You cannot look at an exitcode if thr process has not exited yet, it just means the value is like null still.

As for why SET doesn't work, its because SET is not a command. There are other ways to set the environment variables for a program. And even if you could set that, it would only apply for the scope of that process, which would end after the set command was fired. So it would not be valid for the next Process object.

For your actual process object, look at .EnvironmentVariables on the ProcessStartObject
Sep 12 '08 #5
rhitam30111985
112 100+
Haha, yeah of course they will. You cannot look at an exitcode if thr process has not exited yet, it just means the value is like null still.

As for why SET doesn't work, its because SET is not a command. There are other ways to set the environment variables for a program. And even if you could set that, it would only apply for the scope of that process, which would end after the set command was fired. So it would not be valid for the next Process object.


i see .... . will look into it.. thanks a lot :)
Sep 12 '08 #6
Plater
7,872 Expert 4TB
Something like this maybe? You might have to expand out the %programfiles% string with procStartInfo.EnvironmentVariables["%programfiles%"], but I don't think so
Expand|Select|Wrap|Line Numbers
  1. System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd", @"/c  MSDEV C:\Shared\Source\Binaries\Project\Project.dsp /MAKE  /REBUILD >> compilerr.txt");
  2. procStartInfo.EnvironmentVariables["path"]=procStartInfo.EnvironmentVariables["path"]+@";%programfiles%\Microsoft Visual Studio\Common\MSDev98\Bin;";
  3. procStartInfo.UseShellExecute = false;
  4. System.Diagnostics.Process proc = new System.Diagnostics.Process();
  5. proc.StartInfo = procStartInfo;
  6. proc.Start();
  7.  
Sep 12 '08 #7
rhitam30111985
112 100+
Something like this maybe? You might have to expand out the %programfiles% string with procStartInfo.EnvironmentVariables["%programfiles%"], but I don't think so
Expand|Select|Wrap|Line Numbers
  1. System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd", @"/c  MSDEV C:\Shared\Source\Binaries\Project\Project.dsp /MAKE  /REBUILD >> compilerr.txt");
  2. procStartInfo.EnvironmentVariables["path"]=procStartInfo.EnvironmentVariables["path"]+@";%programfiles%\Microsoft Visual Studio\Common\MSDev98\Bin;";
  3. procStartInfo.UseShellExecute = false;
  4. System.Diagnostics.Process proc = new System.Diagnostics.Process();
  5. proc.StartInfo = procStartInfo;
  6. proc.Start();
  7.  

procStartInfo.EnvironmentVariables["%programfiles%"] returns blank value .. hence the path had to be hardcoded ..even %systemroot% is not working ... apart from that it works like a charm :-)
Sep 15 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: marccruz | last post by:
Given an instance of System.Diagnostics.Process, how can I get the parent process o Given an instance of System.Diagnostics.Process, how can I get the child processes For example, I start a...
1
by: Heiko Besemann | last post by:
Dear group, I created an aspx page using System.Diagnostics.Process() to launch "tracert" from shell and redirect output to Response.Output which prints it as text/plain into my browsers window....
1
by: solex | last post by:
Hello All, Hopefully someone has run into this error. I have written a class(source below) that launches a thread to monitor the StandardOutput of a System.Diagnostics.Process, in particular I...
2
by: andreas | last post by:
hi, In windows xp in the start launch menu when i put notepad "c:\test.txt" i get notepad with test.txt in it. in vb.net when i state system.diagnostics.process.start("notepad.exe" i get...
11
by: Nurit N | last post by:
This is the third newsgroup that I'm posting my problem. I'm sorry for the multiple posts but the matter becoming urgent. I hope this is the right place for it... I have created a very...
0
by: Daniel | last post by:
System.Diagnostics.Process.Start fails on windows server 2003 the process returns process.ExitCode == 0 but executing any process with System.Diagnostics.Process.Start on windows xp works fine....
0
by: Daniel | last post by:
C# windows service freezes on System.Diagnostics.Process.Start(info) When I launch PSCP from a C# windows service and launch pscp 0.53 there are no issues. but when I use C# windows service to...
0
by: Colin Williams | last post by:
I am using the code below to map network drive and then fire up an app in a sub dir of that drive. However when using the file open dialog from that app, drive K: appears just as Network drive K:...
0
by: =?Utf-8?B?UHVjY2E=?= | last post by:
-- Hi I'm using vs2005, .net 2 for windows application. The application I started using System.Diagnostics.Process is having a "listFiles.StandardOutput" buffer size problem. I was wondering...
2
by: test3 | last post by:
Hello folks, I'm using System.Diagnostics.Process to start a thirdparty program (that works perfectly when started via command line). I'm using Process.StandardOutput to get the output of the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.