Command Line Argument with & and ^

M

mackmelo

Hi,

I'm trying to create a program that reads these two characters (& and
^) as arguments to a funcion. However since they are part of the
operational system characters with special funcions when in an
argumento to a function, whenever I put them in my list of arguments, I
get errors and can't parse them to my program.

Any Ideas on how to use them inside my application? Ah, and i don't
want to use other arguments before them so it can be recognized, like
/^ or -&, ofr example.

Thanks a lot for any help.
 
M

mackmelo

Hi,

I'm sorry, but this is not off-topic. Maybe I didn't explain myself
very clearly.

I'm creating a C++ application that needs command line arguments (argv
and argc). The problem is that when I try to use ^and & in the command
line - for example (the name of the program is run.exe):

run asdf jasdas ^

I should get three arguments (other than the program itself) but I
can't read the last argument, the ^. When I try the & a different error
occurs, but it seems to be the same problem. ^ and & are reserved
arguments used by the operational system to do something at the command
line.

What should I do inside my code (C++) to get these arguments as valid
and accountable argumetns?

I hope that with this explanation you may consider this post as
on-topic.

Thanks.
 
L

Larry I Smith

mackmelo said:
Hi,

I'm sorry, but this is not off-topic. Maybe I didn't explain myself
very clearly.

I'm creating a C++ application that needs command line arguments (argv
and argc). The problem is that when I try to use ^and & in the command
line - for example (the name of the program is run.exe):

run asdf jasdas ^

I should get three arguments (other than the program itself) but I
can't read the last argument, the ^. When I try the & a different error
occurs, but it seems to be the same problem. ^ and & are reserved
arguments used by the operational system to do something at the command
line.

What should I do inside my code (C++) to get these arguments as valid
and accountable argumetns?

I hope that with this explanation you may consider this post as
on-topic.

Thanks.

There is nothing you can do in the C++ code.
The system's command parser processes those special symbols even
before it starts your program.

Those characters as 'special' on many Operating Systems, stick
with alphanumerics

Larry
 
A

Alf P. Steinbach

* mackmelo:
I'm sorry, but this is not off-topic. Maybe I didn't explain myself
very clearly.

It is 100% off-topic, and you did explain it very clearly.

It is purely an issue with one specific Microsoft Windows program
(namely, the Windows program [cmd.exe]), and so has /nothing whatsoever/
to do with any programming language, much less C++.

Please post to an appropriate newsgroup, such as e.g.
[comp.os.ms-windows.programmer.win32].
 
M

mackmelo

Hello,

I want to thank you for your answers and that the language can't deal
with these characters. I'll try to explain this to my professor and I
really hope he accepts this explanation. :)

Thanks for your help.
 
L

Larry I Smith

mackmelo said:
Hello,

I want to thank you for your answers and that the language can't deal
with these characters. I'll try to explain this to my professor and I
really hope he accepts this explanation. :)

Thanks for your help.

I think you misunderstand...

The languge (your program) never sees these characters.
The characters are interpreted by the Operating System
(and possibly discarded) before the Operating System
even launches your program. The Operating System
does not pass these chars to your program - that's not
the program (or the language's fault).

Larry
 
K

Kodt

Alf said:
* mackmelo:
I'm sorry, but this is not off-topic. Maybe I didn't explain myself
very clearly.

It is 100% off-topic, and you did explain it very clearly.

It is purely an issue with one specific Microsoft Windows program
(namely, the Windows program [cmd.exe]), and so has /nothing whatsoever/
to do with any programming language, much less C++.

Please post to an appropriate newsgroup, such as e.g.
[comp.os.ms-windows.programmer.win32].

Brief explanation, as the question is asked.

cmd.exe interprets '^' as an escape character (like '\' in C/C++
strings).
For example, a command
echo hello > world
passes "hello" to echo and forwards its output to a file "world"
To escape control characters of command line, use ^ prefix:
echo hello ^>^^.^^^< my name is Neko
passes "hello >^.^< my name is Neko" to echo and doesn't redirect.

& means serial execution of commands
echo hello & echo world
is treated as
echo hello
echo world
To escape &, use ^ as above.
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top