command line processing question

N

News

Hi folks I've got a really easy question yet I can't seem to get an answer from any book.
I am playing around with ARGV and ARGC and I think I understand the use of these parameters pretty well but I just can't see to figure out how to execute the program from the command line. My file is test.cpp and the paramter is to print something. Here are my questions:

At the command prompt I type:
a.. "test Mike "... file not recognize.
b.. "test.exe Mike" ... file not recognized
c.. "test.cpp Mike" ... cmd window minimizes but now print out to the screen.
Yes, I have the right print statement ... cout << "print something" << endl.

1. Is there a switch or option that I need to turn on to compile the program into a *.exe file or something?
2. What is the format that I am looking to execute *.cpp, *.c, *.exe ....?
3. Is there are particular place that "this" file type is stored perhaps that is different then the *.cpp/c files?
4. Is there are preprocessor directive that I need to enter into the code?

I am stumped.
FYI -- I am using MS Visual Studio C++ (Studio.net 2003)

Any help is much appreciated!

Dave
 
G

Gianni Mariani

News wrote:
....
Any help is much appreciated!

a) There is a standard program called - you guessed it - "test" on some
systems so it's a bad idea to write your own.

b) You need to check that your command line processor is looking in the
right directory for your executable. This is usually in the path or
PATH environment variable.

c) You can specify the fully qualified name to your executable file. e.g.
./test or .\test depending on os

d) various IDE's will place your executable in wierd places like Debug,
Release, work.gx86_32 etc. Make sure you know where it is being created.
 
A

Alf P. Steinbach

* News:
Hi folks I've got a really easy question yet I can't seem to get an
answer from any book.
I am playing around with ARGV and ARGC and I think I understand the use
of these parameters pretty well but I just can't see to figure out how
to execute the program from the command line. My file is test.cpp and
the paramter is to print something. Here are my questions:

At the command prompt I type:

* "test Mike "... file not recognize.
* "test.exe Mike" ... file not recognized
* "test.cpp Mike" ... cmd window minimizes but now print out to
the screen.

Yes, I have the right print statement ... cout << "print something" << endl.

1. Is there a switch or option that I need to turn on to compile the
program into a *.exe file or something?

In addition to Gianni's comments, it might help you to try to run some
other programs from the command prompt.

Since it seems you're using Windows, try running internet exploder,
which is the program [iexplore.exe].

I'm choosing that program as an example precisely because it's not one
that's automatically found (unless you use a special command), i.e. just
typing "iexplore" you'll most probably get a "not recognized" failure
message, so you'll have to go the directory (folder) where it resides,
or specify a path, thus learning about the basics of running program.

By the way, this is off-topic here in [clc++], but anything to get an
enthusiastic novice up and running! ;-)

Just ask in a more appropriate group for more details (e.g. perhaps in
[comp.os.ms-windows.programmer.win32] for truly Windows-specific things,
and [alt.comp.lang.learn.c-c++] for basic C++ stuff).

Cheers, & hth.,

- Alf
 
J

Jim Langston

Gianni Mariani said:
News wrote:
...

a) There is a standard program called - you guessed it - "test" on some
systems so it's a bad idea to write your own.

b) You need to check that your command line processor is looking in the
right directory for your executable. This is usually in the path or PATH
environment variable.

c) You can specify the fully qualified name to your executable file. e.g.
./test or .\test depending on os

d) various IDE's will place your executable in wierd places like Debug,
Release, work.gx86_32 etc. Make sure you know where it is being created.

a) Is interesting. Since the very first time I got on a unix box I decided
to write a test program in c and called it test.c For an hour I kept trying
to figure out why my program wouldn't output anything no matter how many
times I modified it. Finally I got fed up, deleted my program and ran test
just to make sure it would give me an error, which it didn't. It came back
with the prompt. His eyes open wide. Sure enough, there was a system
command called test, and in this version of unix (if not all) the local
directory was checked after the system directories. Lesson learned.

b/c) Is probably what's happening this person since windows is giving him a
command not recognized. Most likely my guess is he's using some version of
VC++, is in the path of his .cpp file, but isn't aware that his program
actually gets compiled into a subdirectory debug or active. I suspect
debug\test Mike
would probalby do it for him.
 
J

James Kanze

a) Is interesting. Since the very first time I got on a unix
box I decided to write a test program in c and called it
test.c.

Don't feel bad. I still get caught out by the built in
occasionally, and I've worked almost exclusively under Unix for
over 20 years. Of course, ./test works. (And if you compile by
simply invoking "CC test.c", the name of the executable is
a.out.)
For an hour I kept trying to figure out why my program
wouldn't output anything no matter how many times I modified
it. Finally I got fed up, deleted my program and ran test
just to make sure it would give me an error, which it didn't.
It came back with the prompt. His eyes open wide. Sure
enough, there was a system command called test, and in this
version of unix (if not all) the local directory was checked
after the system directories. Lesson learned.

The order directories are checked depends on the $PATH variable
(the same as in Windows, I think). The problem is that test is
(usually) a shell built-in, so the shell doesn't even look in
any of the directories.
b/c) Is probably what's happening this person since windows is giving him a
command not recognized.
From the way he formulated his question, it sounds more like he
doesn't even know that he needs to compile the code. (He's at
the command prompt, which suggests that he isn't even in Visual
Studios. Otherwise, he'd have invoked the program from Visual
Studios, and probably be complaining that the Window was being
closed too soon:).) If that's the case, it should be
sufficiant that he invoke "cl test.cc" before trying to execute
(and I would still use the relative pathname, .\test, rather
than counting on whatever shell he's using to not have test as a
builtin, and to look first in the current directory).
 
J

James Kanze

[...]
I'm choosing that program as an example precisely because it's not one
that's automatically found (unless you use a special command), i.e. just
typing "iexplore" you'll most probably get a "not recognized" failure
message, so you'll have to go the directory (folder) where it resides,
or specify a path, thus learning about the basics of running program.

Very good advice. (I don't know about iexplore, but in general,
learning to use the system you are on is a good idea.)
By the way, this is off-topic here in [clc++], but anything to get an
enthusiastic novice up and running! ;-)
:)

Just ask in a more appropriate group for more details (e.g. perhaps in
[comp.os.ms-windows.programmer.win32] for truly Windows-specific things,
and [alt.comp.lang.learn.c-c++] for basic C++ stuff).

I wonder about this. Does anyone developing under Windows
actually use the "standard" command interpreter? (I've never
seen a Windows developer who didn't have either bash or ksh
installed.)
 
J

Jerry Coffin

[ ... ]
I wonder about this. Does anyone developing under Windows
actually use the "standard" command interpreter? (I've never
seen a Windows developer who didn't have either bash or ksh
installed.)

I have bash installed, but I use Microsoft's standard command
interpreter considerably more often.
 
J

Jim Langston

[...]
I'm choosing that program as an example precisely because it's not one
that's automatically found (unless you use a special command), i.e. just
typing "iexplore" you'll most probably get a "not recognized" failure
message, so you'll have to go the directory (folder) where it resides,
or specify a path, thus learning about the basics of running program.

Very good advice. (I don't know about iexplore, but in general,
learning to use the system you are on is a good idea.)
By the way, this is off-topic here in [clc++], but anything to get an
enthusiastic novice up and running! ;-)
:)

Just ask in a more appropriate group for more details (e.g. perhaps in
[comp.os.ms-windows.programmer.win32] for truly Windows-specific things,
and [alt.comp.lang.learn.c-c++] for basic C++ stuff).

I wonder about this. Does anyone developing under Windows
actually use the "standard" command interpreter? (I've never
seen a Windows developer who didn't have either bash or ksh
installed.)

=======

I just use MSVC++ .net 2003 and the command prompt when I need it. But
then, I've been using MS-DOS since 2.0 so am used to it.
 
J

James Kanze

I just use MSVC++ .net 2003 and the command prompt when I need
it. But then, I've been using MS-DOS since 2.0 so am used to
it.

I used MS-DOS 2.3 for awhile, but even then, I had the Korn
shell installed. (Back then, the MKS Toolkit was still
affordable.) I did use the standard "shell" for a while: at the
time, I actually knew it fairly well; enough to write .bat
files.

I guess part of the reason everyone I see installs bash and ksh
is that I've only seen Windows in mixed environments, where
there was also a lot of Unix. It's easier to just deal with one
command interpreter, rather than two, and of course bash/ksh is
more powerful than the standard command interpreter under
Windows. Similarly, the standard editor under Windows, for most
the people I know, is either emacs or vim (but some of those
developing pure Windows do use the Visual Studios editor).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,522
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top