You are here:

C++/command line in Windows



How are you? Thank you for taking questions. I wrote a command line (console) program in C for Linux and compiled it. In order to run it I just do this

./MYPROGRAM -myargument1 -myargument2

Now I'd like to compile this for Windows and run it in Windows but I don't know how. I can open Windows console and I can write a simple "Hello World" console application in Windows that interacts with the user and asks for input but I cannot use it the same way I use it in Linux. I cannot type in my command line as shown above and have it run the same way. Would you be able to help? Perhaps there is a tutorial somewhere. I use Qt/QMAKE to produce and compile my C/C++ programs but I don't this makes any difference.


ANSWER: Hello friend,
To run your programme using Windows cmd line:
Open the cmd line and type cl programe.c
This creates an executable for you. Finally type in the executable and you should be anke to see your output.
Stay cool :)

---------- FOLLOW-UP ----------


Thanks for your answer. Actually what I meant was that I have a program in C and I can compile it under Windows just fine. I just don't know how to run it. It doesn't seem to work the same way as in Linux. It wants to run immediately as soon as I click on it but I'd like to enter the arguments before I run run it; just like I do it under Linux: ./MYPROGRAM -argumet1 5 -argument2 6 etc.

Basically I do not understand how the Windows terminal window functions. It is very different from Linux.


ANSWER: Hello,
Go to the directory your .exe file is and do this on the cmd line:
Filename.exe arg1 arg2
Where Filename is the name of the executable
I misunderstood the question at first.

---------- FOLLOW-UP ----------


Thank you very much!
May I also ask how to specify switches.

A Linux example:

./MYPROGRAM -file myfile -output newfile

I don't think this will work in Windows:

MYPROGRAM.exe -file myfile -output newfile

It doesn't seem to understand my switches.


Hello for windows switches , try this link :

I do not know exactly what your programme is to do but I have shown you how to use switches in windows. Now, you can use the link to find the switch you want and apply it to your executable. note, if you have a path like c:/folder1/programme.exe then it is wise to enclose it in a double colon like this : "c:/folder1/programme.exe" -switch1 -switch2


All Answers

Answers by Expert:

Ask Experts




I can confidently answer any question both basic and advanced in C++. Areas like templates, algorithms, Gui and design patterns are of interest to me. i will not answer questions about web programming.


I have a 3- year- work experience in software Engineering.

I am a bachelor of Engineering graduate

©2016 All rights reserved.