How to run a .exe file with command prompt?

懵懂的女人 提交于 2019-12-24 07:07:16

问题


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

回答1:


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



回答2:


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.




回答3:


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




回答4:


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




回答5:


You can install TCC

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

or else try the option ./HelloWorld



来源:https://stackoverflow.com/questions/13549877/how-to-run-a-exe-file-with-command-prompt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!