Command Line Argument with & and ^

Discussion in 'C++' started by mackmelo, Apr 2, 2006.

  1. mackmelo

    mackmelo Guest

    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.
     
    mackmelo, Apr 2, 2006
    #1
    1. Advertising

  2. * 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?
     
    Alf P. Steinbach, Apr 2, 2006
    #2
    1. Advertising

  3. mackmelo

    mackmelo Guest

    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.
     
    mackmelo, Apr 3, 2006
    #3
  4. 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
     
    Larry I Smith, Apr 3, 2006
    #4
  5. * 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?
     
    Alf P. Steinbach, Apr 3, 2006
    #5
  6. mackmelo

    mackmelo Guest

    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.
     
    mackmelo, Apr 3, 2006
    #6
  7. 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
     
    Larry I Smith, Apr 3, 2006
    #7
  8. mackmelo

    Kodt Guest

    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.
     
    Kodt, Apr 3, 2006
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fong
    Replies:
    3
    Views:
    1,191
  2. Thomas Kellerer
    Replies:
    5
    Views:
    34,641
    Nomak
    Apr 13, 2005
  3. Justin Naidl

    Command line argument problems

    Justin Naidl, Sep 17, 2004, in forum: C++
    Replies:
    2
    Views:
    445
    Niels Dekker - no reply address
    Sep 18, 2004
  4. nic977

    reading in command line argument

    nic977, Sep 12, 2003, in forum: C Programming
    Replies:
    13
    Views:
    612
    Dave Thompson
    Sep 22, 2003
  5. manouchk

    nsis and command-line argument

    manouchk, Jan 18, 2007, in forum: Python
    Replies:
    1
    Views:
    675
    manouchk
    Jan 19, 2007
Loading...

Share This Page