Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Command Line Argument with & and ^ (http://www.velocityreviews.com/forums/t453032-command-line-argument-with-and-and.html)

mackmelo 04-02-2006 09:51 PM

Command Line Argument with & and ^
 
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.


Alf P. Steinbach 04-02-2006 09:58 PM

Re: Command Line Argument with & and ^
 
* mackmelo:
> [off-topic]


Please post OS-related question in a newsgroup for that OS.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

mackmelo 04-02-2006 11:01 PM

Re: Command Line Argument with & and ^
 
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.


Larry I Smith 04-02-2006 11:18 PM

Re: Command Line Argument with & and ^
 
mackmelo wrote:
> 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

Alf P. Steinbach 04-02-2006 11:23 PM

Re: Command Line Argument with & and ^
 
* 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].

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

mackmelo 04-03-2006 03:14 AM

Re: Command Line Argument with & and ^
 
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.


Larry I Smith 04-03-2006 03:31 AM

Re: Command Line Argument with & and ^
 
mackmelo wrote:
> 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

Kodt 04-03-2006 10:08 AM

Re: Command Line Argument with & and ^
 
Alf P. Steinbach wrote:
> * 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.



All times are GMT. The time now is 09:47 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.