开发者

How do we write a program in Command line development environment?

I have been writing my code in IDE,I just read that there also existed a Command Line Development Environment in which the code is written in DOS.I googled but found no results on how to use the command line development environment.My OS开发者_开发知识库 is Windows XP.I would be very thankful for your help me write the hello world program in DOS and also explain how to run it.


You simply use whatever text editor you like to create the C sourse file(s) then invoke the compiler command line(s) to compile and link the program (typically, an IDE is doing exactly that, but in a behind-the-scene manner). How the command line is invoked depends on the exact toolchain you're using.

You might also need to set up an environment for you particular compiler toolchain (the right paths and various other env variables might need set up).

For Visual C++ the environment might be set up using a batch file installed by Visual Studio:

vcvarsall x86

Invoking the compiler could be as simple as:

cl helloworld.c

or for C++ (for some reason it issues a non-fatal warning if you don't give it an option configuring details about how it should implement exceptions):

cl  /EHsc helloworld.cpp

The particulars are very dependent on the compiler you're using - you should read the docs for that compiler.

Also, the options you use depend on your particular situation and needs. Scripts/batch files and/or makefile can help you manage the complexity of the options you might need to use.


DOS is not dead.... yet!

fahad

There are a number of methods by which you can enter code in DOS (see EDIT further on down).


(1) You can send keystrokes directly to a file

You do this by redirecting output to CON (the console) to a file. The only oddity of this method is that you end the 'session' by entering a CTRL-Z when you are finished.

It's basic, but this is how it goes.

Firstly, suppose you want to display "Hello World" on the screen, a simple batch file containing the following two lines is all that is required:

   @echo off
   echo Hello World

The '@echo off' is commonly found at the start of all batch files. It simply instructs the command interpretter NOT to display each command as it is being executed (or parsed).

One more thing before we start. Throughout this answer, I will assume your program is named 'helloworld.bat'.

Enter the following lines one after the other pressing the ENTER key at the end of each line:

   copy con helloworld.bat
   @echo off
   echo Hello World
   ^Z

The '^Z' is displayed when you press the CTRL-Z key combination (don't forget to press the ENTER key as well).

When you press the ENTER key after CTRL-Z, DOS displays the familiar '1 File(s) copied' messege.

You can now execute the batch file program by simply entering the program's name like this:

   helloworld

And DOS will display the following:

   Hello World

It can't get any more basic than that.


(2) You can use DOS' EDIT program

This is a DOS based IDE retained from around the mid-90's. Simply enter the following command:

   edit

And EDIT will open in the same DOS window. When you close EDIT, you are returned back to DOS again.

EDIT also works with your mouse.

Once EDIT opens, enter the following two lines of code:

   @echo off
   echo Hello World

Then, click on [File], [Save], type: 'helloworld.bat' in the "File Name" input field, use your mouse to change directories in the "Directories:" pane if you want to, then click [OK]. To return to DOS, click [File], [Exit].

EDIT version 4.5 (I think) was context-sensitive and displayed code using different colours to seperate key word, different data type, symbols etc.


(3) Use Windows' built-in Notepad

This is simple. At the command prompt, enter the following command:

   notepad

And Notepad will fire up. It's a simple text editor and does the job when entering small programs.


(4) Use Notepad++. It's FREE!!

Notepad++ is the programmer's choice. It's free, full of useful features and customisable. Find it on the net by searching for "notepad++".



From your comment, "Just some knowledge so I can say that I know one way to do programming without IDE" I would say learn to write simple batch files. They can be run from Explorer but they exist as a holdover from the DOS days.

Start a command prompt window (Start->Run->'cmd'), this will open a window and show a prompt, most likely "c:\" or some other path.

Type the following command (followed by )

echo "Hello World"

You should see:

"Hello World"  
c:\

Now, using whatever editor you'd like, create a text file with that command as the only line. Name the file "hello.bat". When you are at the command prompt you can execute the batch file like so:

c:\hello.bat
"Hello World"
c:\

You have now programmed using the DOS command line. For more commands and such, start with the help system.

c:\help

Which will display all the available commands for your batch file.
Microsoft has an online reference here.


DOS is dead for all practical purposes. Under Windows your options boil down to the following:

  • Use an IDE. Visual Studio is one example, Qt another. You can write programs for the commandline with an IDE.
  • Use a proper text editor, build tool and other helper tools. You might use gvim for editing code, make for building your project and git for version control. You might as well use the GNU coreutils for other helpers, or maybe even the entire cygwin package.


Bro, use gcc compiler for which write ur code in any text editor then compile ur code in windows shell or u can say command line environment.

Look!

Prompt:/> gcc source_file_name.c

This command compiles ur code, If there is any error, u will get dispalyed with line numbers, now, every program creates its exe file by the name a.exe by default. To, get the output of ur program,

Prompt:/> a.exe

O/P

Hello World!

To change the name of the exe file there is also a command..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜