473,938 Members | 8,174 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# .net system.diagnost ics.process

rhitam30111985
112 New Member
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.Invalid OperationExcept ion'

and for the msdev command :

'proc.BasePrior ity' threw an exception of type 'System.Invalid OperationExcept ion'


Any idea where i could be going wrong ?

Thanks a lot ,

Rhitam
Sep 12 '08 #1
7 15862
Plater
7,872 Recognized Expert Expert
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 New Member
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 New Member
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.Diagnost ics.Process.Sta rtWithCreatePro cess(ProcessSta rtInfo startInfo)
at System.Diagnost ics.Process.Sta rt()
at System.Diagnost ics.Process.Sta rt(ProcessStart Info startInfo)
at GetBuildSource. Program.Main(St ring[] args) in C:\Shared\Test Environment\Get BuildSource\Pro gram.cs:line 39
at System.AppDomai n._nExecuteAsse mbly(Assembly assembly, String[] args)
at System.AppDomai n.ExecuteAssemb ly(String assemblyFile, Evidence assemblySecurit y, String[] args)
at Microsoft.Visua lStudio.Hosting Process.HostPro c.RunUsersAssem bly()
at System.Threadin g.ThreadHelper. ThreadStart_Con text(Object state)
at System.Threadin g.ExecutionCont ext.Run(Executi onContext executionContex t, ContextCallback callback, Object state)
at System.Threadin g.ThreadHelper. ThreadStart()
Sep 12 '08 #4
Plater
7,872 Recognized Expert Expert
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 .EnvironmentVar iables on the ProcessStartObj ect
Sep 12 '08 #5
rhitam30111985
112 New Member
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 Recognized Expert Expert
Something like this maybe? You might have to expand out the %programfiles% string with procStartInfo.E nvironmentVaria bles["%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 New Member
Something like this maybe? You might have to expand out the %programfiles% string with procStartInfo.E nvironmentVaria bles["%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.E nvironmentVaria bles["%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
1754
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 process which executes a script that starts a java program System.Diagnostics.Process proc = System.Diagnostics.Process() proc.StartInfo.FileName = "test.bat"
1
3074
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. Now that works fine so far. My problem is that while tracert process is running and ASP ..NET is putting data into the pages output stream, my webapplication is locked until tracert process exits. How can I stop locking my application and be...
1
6013
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 am executing the find.exe program. The application works perfectly in the development environment. As soon as I execute the compiled program and start the find process I get an "Application Error". The error states that the instruction...
2
15483
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 notepad but
11
3774
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 simple batch file (echo hello world) and was trying to retrieve the standard output but every time I run the code it returns ExitCode as 1.
0
1812
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. anything to do different for windows server 2003? some special permission for the process that executes another executable with System.Diagnostics.Process.Start ?? here is the code:
0
849
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 launch pscp 0.58 C# freezes in System.Diagnostics.Process.Start(info)? pscp 0.58 works fine at command line, but causes C# to freeze on ystem.Diagnostics.Process.Start(info) also i noticed that the pscp process does not show in taske manager while...
0
4233
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: (this could confuse users) rather than showing the path it is mapped to like in explorer. Using a batch file to execute these commands works great. Any ideas? System.Diagnostics.Process.Start("net.exe", "use K:...
0
3031
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 where and how can I adjust the buffer size problem. I don't want to be limited to a set buffer size, is that possible? thank you. public static int GetNisFile(System.Diagnostics.ProcessStartInfo psi, ref DataTable dtAccounts, ref...
2
6898
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 program. That works for 95 %, but the other 5 % it doesn't. It seems to me that the started process just hangs, and therefor my program hangs, too (p.WaitForExit()). I researched that this only happens when the output of the program is longer than...
0
11507
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
11089
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11280
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10648
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9850
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6072
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4899
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4441
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3495
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.