Command Line Arguments

Welcome Forums General PowerShell Q&A Command Line Arguments

This topic contains 11 replies, has 3 voices, and was last updated by

 
Participant
2 years, 5 months ago.

  • Author
    Posts
  • #39166

    Participant
    Points: 0
    Rank: Member

    Morning Guys

    Wondered if you could help. I'm trying to send the following command line arguments to the Cisco Anywhere connect VPN command line without much luck.

    I need to pass:

    –s < C:\Temp\Connect.txt To 'C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client\vpncli.exe' So the line should like: 'C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client\vpncli.exe' –s < C:\Temp\Connect.txt The issue seems to be the < I've tried multiple ways but with no joy, can anyone help me please? Many thanks Barry

  • #39169

    Participant
    Points: 6
    Rank: Member

    Try this:

    & 'C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client\vpncli.exe' --% –s < C:\Temp\Connect.txt
    
  • #39171

    Participant
    Points: 0
    Rank: Member

    Hi Richard

    Thanks for your reply. I did try that before and it fails with

    The '<' operator is reserved for future use. Thanks Barry

  • #39172

    Participant
    Points: 6
    Rank: Member

    That is strange. PowerShell should ignore what is coming after the –% and pass it to the referenced executable. You're using a double dash?

  • #39174

    Participant
    Points: 0
    Rank: Member

    Yep def, just doubled checked.

    Thanks

  • #39178

    Member
    Points: 0
    Rank: Member

    That symbol isn't actually passed to the executable. Whatever documentation you're reading probably assumes that you're running it from cmd.exe, where the < operator is input redirection. Without knowing how their app works, the simplest thing to do in PowerShell is probably just to wrap the call in a call to cmd.exe:

    cmd.exe /c '"C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client\vpncli.exe" –s < C:\Temp\Connect.txt'
    
  • #39179

    Participant
    Points: 0
    Rank: Member

    Hi Dave

    That works perfectly!

    Many thanks for your help

    Barry

  • #39181

    Participant
    Points: 6
    Rank: Member

    Dave, do you know why –% doesn't work in this situation? My impression always was that PowerShell would pass whatever you typed to the executable?

  • #39182

    Member
    Points: 0
    Rank: Member

    I thought so as well, but maybe the pipe and/or redirection operators still take precedence. Haven't played with that much.

  • #39184

    Participant
    Points: 6
    Rank: Member

    Look like a little bug then in the –% escape character. I wonder if you could escape it. But putting it in single quotes is much simpler, as you proposed. 🙂

    @Barry: would you be so nice to try this, to satisfy my curiosity? 🙂 :

    & 'C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client\vpncli.exe' --% –s `< C:\Temp\Connect.txt
    
  • #39185

    Participant
    Points: 0
    Rank: Member

    Hi Richard

    Tried the suggested change and back to the first error:

    The '<' operator is reserved for future use. Thanks Barry

  • #39187

    Participant
    Points: 6
    Rank: Member

    Thanks Barry! Seems indeed that redirection characters cannot be parsed with the –% escape character as a string. Seems a bug to me.

The topic ‘Command Line Arguments’ is closed to new replies.