Anyone use the Windows command prompt?

  • Thread starter m0bius
  • Start date
  • #1
15
0
Hey all, I decided to start learning some C++ and my book mentions compiling and running programs from the command prompt. I have taken a few classes in computer science, but those dealt mainly with java, along with some algorithms and data structures. Even though I have used computers since I was probably 6, I know nothing about the inner workings of them or how to use the command prompt. After some testing I was finally able to run a program from the command prompt, but the whole process seems very inefficient. Is there some advantage to using the command prompt or a point in learning how to use it?

So let's say I'm trying to compile my C++ program called prog1.c in the prompt. All the help online seems to require the use of Visual C++, but I'm using Code::Blocks for my compiler/IDE. I'm not even sure if I can do what I want in the prompt. Can you compile prog1.c, choose a new file extension for the compiled version, choose a folder to save it in, then run that file all using the prompt? I know I can do this easily through the Code::Blocks IDE but I'd like to learn how to use the prompt. Thanks for any help.

m0bius
 

Answers and Replies

  • #2
I like Serena
Homework Helper
6,577
176
Nowadays I use the Windows command prompt mostly as a shortcut to various programs.
Furthermore, there's a couple of diagnostics that should be run from the command prompt, such as:
C> netstat
C> ping google.com
C> ipconfig /all
to diagnose networking problems.

To program in C++ I would definitely recommend a graphical IDE interface.
For Windows that would be Microsoft Visual Studio, or if you can't get it, I can recommend Eclipse (for which you'll need cygwin).

However, if you want a useful command prompt I can recommend cygwin (http://www.cygwin.com), which basically is "linux in Windows".
This is because the linux command line is very powerful with all the tools that come with it.
This includes a command-line C++ compiler (g++), which is used by Eclipse if you install that.

[edit]Btw, I am unfamiliar with Code::Blocks.[/edit]
 
Last edited:
  • #3
jhae2.718
Gold Member
1,161
20
MS also has a more powerful CLI called, IIRC, PowerShell.

I haven't used it much; I do all my serious stuff on Linux.
 
  • #4
rcgldr
Homework Helper
8,710
538
In the case of Visual Studio, you have the option of clicking on start / programs / visual studio ... / tools / visual studio command prompt, or ... visual studio x64 cross tools command prompt. This will let you manually compile programs and run them from a dos console window, just like going back to the days of msdos.

Even in the msdos days, there were window like IDE's like Borlands Turbo products, and Microsoft's programmwers workbench.

As far as using command prompt in general, I use it a lot to run batch files, such as a batch file to backup save files that may be scattered in different directories, for a game as I go through it's career mode, or to backup "favorites" and email .dbx files, using some command line compression utility that creates .rar or .zip files. I also have a collection of old command prompt programs that I sometimes compile and run from a dos console window.
 
  • #5
15
0
Hey, thanks for the replies.

I like Serena said:
For Windows that would be Microsoft Visual Studio, or if you can't get it, I can recommend Eclipse (for which you'll need cygwin).
I used Eclipse for Java, but when I tried to find a way to program C++ in Eclipse I couldn't figure out how to get it to work for some reason. I'd like to use Eclipse for both Java and C++ and be able to swap languages between the two easily. I don't remember reading about cygwin, although I've found some stuff about it online.

On a side note...I can't get this simple code to do what it should :

Code:
#include <iostream>
int main()
{
    std::cout << "Enter two numbers:" << std::endl;
    int v1, v2;
    std::cin >> v1 >> v2;
    std::cout << "The sum of " << v1 << "and " << v2 << "is " << v1 + v2 << std::endl;
    return 0;
}
All I get is "Nothing to be done" from the IDE. I copied it directly from the book so I think it's something wrong with the IDE, but I just want to make sure.

Thanks,
m0bius.
 
  • #6
I like Serena
Homework Helper
6,577
176
Hey, thanks for the replies.



I used Eclipse for Java, but when I tried to find a way to program C++ in Eclipse I couldn't figure out how to get it to work for some reason. I'd like to use Eclipse for both Java and C++ and be able to swap languages between the two easily. I don't remember reading about cygwin, although I've found some stuff about it online.

On a side note...I can't get this simple code to do what it should :

All I get is "Nothing to be done" from the IDE. I copied it directly from the book so I think it's something wrong with the IDE, but I just want to make sure.

Thanks,
m0bius.
The problem will be that you did not install the Eclipse CDT (C/C++ Development Tooling) plugin, which you need to develop in C++.
I found this page that explains how to do it:
http://www.codeproject.com/KB/tips/CPP_Dev_eclipse_CDT.aspx

Note that it also describes you need to install the MinGW package, which contains the actual C++ compiler.
With this one you won't need cygwin.
 
  • #7
133
0
Hey all, I decided to start learning some C++ and my book mentions compiling and running programs from the command prompt. I have taken a few classes in computer science, but those dealt mainly with java, along with some algorithms and data structures. Even though I have used computers since I was probably 6, I know nothing about the inner workings of them or how to use the command prompt. After some testing I was finally able to run a program from the command prompt, but the whole process seems very inefficient. Is there some advantage to using the command prompt or a point in learning how to use it?
I'm curious to know specifically what you found "inefficient" about the command line...

The command line is a powerful tool. That's why it continues to be shipped with every commercial operating system, even including MS Windows and MacOS X. A lot of useful, powerful but legacy tools exist as command line programs so it's useful just for that...

...but it's useful for so much more than that. Command line programs have a very simple and thus standard input and output method: text. This allows for the chaining of commands. That is to say, you can use the output of one program as the input of another. This obviously lends greater functionality to an otherwise disparate collection of programs. It is also useful for automating tasks.

If your program has minimal user interaction, it may be much simpler to implement it as a command line program. This is especially useful if you're learning to or teaching someone how to program. They can concentrate on the fundamental concepts without being distracted by the complexity of GUI programming...

So let's say I'm trying to compile my C++ program called prog1.c in the prompt. All the help online seems to require the use of Visual C++, but I'm using Code::Blocks for my compiler/IDE. I'm not even sure if I can do what I want in the prompt. Can you compile prog1.c, choose a new file extension for the compiled version, choose a folder to save it in, then run that file all using the prompt? I know I can do this easily through the Code::Blocks IDE but I'd like to learn how to use the prompt. Thanks for any help.
You know, you don't have to write command line programs using the command line. I'm sure any IDE can compile a command line program and even run it in its debugger!

Typically, if you are compiling from a command line interface, you run a make file (or whatever equivalent your system has). It's a script that executes a list of commands (or a requisite subset thereof) that are necessary for building an application. You configure whatever you need out of the build process in said file and run it. As you can see, anything you might want to do can be done this way...
 
  • #8
15
0
I'm curious to know specifically what you found "inefficient" about the command line...
Well so far all I've done is run a program from it, which was inefficient as I could have just clicked three times rather than writing the whole path out in the prompt. I have no doubt it's very powerful, it's just way over my head right now as I have no clue about what you guys are talking about when you mention what you do with the prompt...

I like Serena said:
The problem will be that you did not install the Eclipse CDT (C/C++ Development Tooling) plugin, which you need to develop in C++.
I was getting this error in Code Blocks, but it came with the MinGW setup which I never installed. Anyway now that I have it installed I'm still getting the same error and I am just beyond frustrated as it isn't finding the compiler automatically like it says it should online and I have no clue what the path is. I've tried C:\Program Files (x86)\CodeBlocks\MinGW\mingw32, but it's still not working. The IDE settings even lists a bunch of programs that should be in the bin subdirectory of the correct path and they are all there.

I want to use Eclipse for C++ but if I can barely handle this I doubt I can figure that out. If I can't figure this out then I'll give that a shot though since the link you gave has a step by step walkthrough.


edit: Ok It's C:\Program Files (x86)\CodeBlocks\MinGW. It seems to be working now.

Thanks
m0bius
 
Last edited:

Related Threads on Anyone use the Windows command prompt?

  • Last Post
Replies
2
Views
2K
  • Last Post
Replies
5
Views
2K
  • Last Post
Replies
11
Views
4K
Replies
1
Views
2K
Replies
6
Views
3K
  • Last Post
Replies
20
Views
6K
Replies
13
Views
5K
Replies
14
Views
7K
Top