简体   繁体   中英

How to run a .exe file with command prompt?

I am making an online judge. This my school project.

I am taking a .c file from the user. I am able to compile the .c file with command prompt. But I don't know how to run this file. I need to run this file, take input from a text file and save output in a text file. The compilation code was:

    gcc main.c -o HelloWorld

I need to run this file, take input from a text file and save output in a text file.

Assuming you're on Linux, this should work:

./HelloWorld < input.txt > output.txt

I assume you're on Linux? If yes, run it with:

./HelloWorld

The ./ is needed so that the shell knows to look for the executable file in the current directory. (Executables are not looked for automatically in the current directory due to security reasons.)

If on Windows, just type its name:

HelloWorld

Appending .exe to the filename is optional.

Redirecting standard input works like this:

HelloWorld < inputfile

Standard output is redirected with > instead:

HelloWorld > outputfile

You can combine both:

HelloWorld < inputfile > outputfile

Just type in the full path. For example, if you compiled the file in %homedrive% with the name dummy.exe , type %homedrive%/dummy.exe .

Also, if you're already in %homedrive% , you can just type dummy.exe .

Edit : Assuming you're on Windows.

When you type HelloWorld in Linux terminal, your system will be searching this program in place, where PATH variable indicates. Most likely it is /bin. You can check your PATH by typing:

echo $PATH    

So, you must precise, that HelloWorld is in concrete dirctory or change $PATH variable.

./HelloWorld

Dot indicates current directory

You can install TCC

 #!/usr/local/bin/tcc -run

or else try the option ./HelloWorld

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM