473,698 Members | 2,522 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Executing a .exe-program with arguments

17 New Member
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 8601
Curtis Rutland
3,256 Recognized Expert Specialist
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.Diagnost ics; 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 Recognized Expert Expert
If you check what this string produces:
Directory.GetCu rrentDirectory( )
(Either with a Console.WriteLi ne(Directory.Ge tCurrentDirecto ry()); or MessageBox.Show (Directory.GetC urrentDirectory ()); )
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
3219
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 trying execute pathprox.exe directly, i could run the application without any errors, but when i'm executing the same using visual basic with the following code, pathprox.exe is unable to link with those files. its giving some errors. i dont have...
6
1778
by: Dave Karmens | last post by:
What is the preferred method of executing .bat or .exe via ASPs
1
443
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
11544
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 MSACCESS.EXE, tries them all, takes the first one it finds, and dies if none is found. Seems to me like at some time or another I was able to clone this .BAT file and implement it with no path. Something about MSACCESS being a registered application.
1
2049
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
1121
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
1502
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
1754
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. Example \ Start.exe Platforms\Sub\Running.dll
3
8880
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) how can i get the solution for this trouble thing.
0
1360
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 executing the old one. I am using Visual Studio 2005 and programming in C#. I have been wrecking my brains for two days and I can't find a possible explanation. These are the things I have tried so far: -Renaming the new EXE and, of course,...
0
8676
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9164
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...
1
8898
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
8870
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
7734
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, and deploymentwithout 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...
1
6524
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 presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3051
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
2332
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.