473,398 Members | 2,188 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,398 software developers and data experts.

Executing a .exe-program with arguments

17
First post, lol.

Please bear with my English, I'm a 14 year old guy from Sweden.

I just started learning C# a few days ago, so I wanted to create something simple (but yet still useful).

I'm making a console application which launches the compilers for different programming languages. So far have I got compilers for Java, C/C++, C# and Pascal. This is how the program works:
1. The user types in the path to the file (s)he wants to compile.
2. The user selects which language the program is written in using numbers.
3. The user decides whether (s)he wants to compile the file or not. This is only to confirm the compiling, so everything doesn't happen too fast, if you understand what I mean.
4. When the user have typed "yes" and pressed Enter, the program uses a void called Compile() to launch the right compiler for each language.
^ This is where the problem appears.

I work using Visual C# 2008 Express Edition. When I save my project, Visual C# automatically generates a folder called whatever the project is called (in this case, FayconCMD). It generates a folder called Release, where the final program is (FayconCMD.exe).
I've copied the C# compiler from .NET v3.5 into this folder. In the program, the "path" to the compiler is only written "csc.exe", because they are in the same folder. But when I try to compile a test file written in C#, I get the error that the program can't find csc.exe. Do you know why this happens?

I also want to launch csc.exe with an argument, the path to file that shall be compiled. How do I add that? If you had compiled the program manually using cmd.exe, you've done this:
1. Changed the directory to where the file is.
(cd <path to the folder where the file to be compiled is>)
2. Typed csc <file name> (assuming you've added the folder where csc is to your environment variables).

Now I want to just launch the csc.exe with the path to the file as an argument, using this method:

Expand|Select|Wrap|Line Numbers
  1. public void Compile()
  2.         {
  3.             System.Diagnostics.Process.Start(pathToCompiler + " " + Path);
  4.         }
To make a long text short, this is my problems:

1. Why can't my program find an .exe-file in the same folder?
2. How do I execute csc.exe with an argument?

Sincerely yours,
Saser
Jul 9 '09 #1
2 8585
Curtis Rutland
3,256 Expert 2GB
OK, to answer your number two question first:
Expand|Select|Wrap|Line Numbers
  1. Process proc = new Process();
  2. proc.StartInfo.FileName = "explorer.exe";
  3. proc.StartInfo.Arguments = "/select," + filepath; 
  4. proc.Start();
There's a sample I gave someone else on how to use arguments. Make sure to either add using System.Diagnostics; or qualify the name. This example simulates the console command:
Expand|Select|Wrap|Line Numbers
  1. explorer.exe /select,somefilename.txt
As to your first question, I'm not sure. How about you try to provide the fully qualified name to the executable.
Jul 9 '09 #2
Plater
7,872 Expert 4TB
If you check what this string produces:
Directory.GetCurrentDirectory()
(Either with a Console.WriteLine(Directory.GetCurrentDirectory()) ; or MessageBox.Show(Directory.GetCurrentDirectory()); )
You can see what directory the program is looking for csc.exe in, it might not be the directory that you think it will be.
Jul 9 '09 #3

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

Similar topics

2
by: Ratnakar Pedagani | last post by:
Hi, I'm trying to execute a GUI application from visual basic (named PathProx.exe). this pathprox.exe is linked to different files that are present in the same directory as pathprox. when i'm...
6
by: Dave Karmens | last post by:
What is the preferred method of executing .bat or .exe via ASPs
1
by: Yoshitha | last post by:
HI I am calling exe (vb.net application) from web application for this i wrote code like this system.diagnosis.process.start("e:\...") i wrote above code in button click event.
15
by: (Pete Cresswell) | last post by:
I've got a .BAT file that I use for executing various MS Access apps that I wrote way back in the days of 2.0. It's evolved over time, but it still contains a number of possible paths to...
1
by: new1s.on.sympatico.ca | last post by:
Hey There! Any one have any ideas on how to prevent the DOS window from appearing when executing an Output Assembly (exe) generated using CodeDom? Thanks, Roland
0
by: Yoshitha | last post by:
HI I am calling exe (vb.net application) from web application for this i wrote code like this system.diagnosis.process.start("e:\...") i wrote above code in button click event.
3
by: Eva | last post by:
Hi All Is it possible to connect to a remote machine running a vb.net application, access the C drive on the remote machine and execute an exe from the server programatically Eva
1
by: Ryan.Mohammed | last post by:
I have a problem where the code that serializes and deserializes an object is actually not the start application but loaded by reflection and located in a subdirectory of the start application. ...
3
by: linear | last post by:
Linking... Creating browse info file... 系统找不到指定的路径。 已复制 0 个文件。 Error executing c:\windows\system32\cmd.exe. ThePlaya.exe - 1 error(s), 57 warning(s)...
0
by: google | last post by:
Hi everyone, >From my WinForms app I am executing an external process. It turns out that I have replaced the EXE of the external process with a newer version and my WinForms app is still...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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:
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...
0
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...
0
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 projectplanning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.