1.    24 Feb 2009 #1
    Raymond Vought Guest

    Running a command from inside a script, command line is corrupted


    Hello,

    I am trying to give Powershell a chance, since it seems like it may have
    some promise.

    I have this powershell script that needs to run an executable occasionally,
    using logic from the script. The executable has a command line that is
    sensitive to spacing so it has to be just right. In particular, my script
    needs to run the wlogevent.exe like this:

    c:\temp\wlogevent.exe -c:41 -l:3 -ss:"String status message here."

    In cmd.exe, wlogevent works when called as above. But if you try to run
    wlogevent with spaces after the colons it it's command line like this

    c:\temp\wlogevent.exe -c: 41 -l: 3 -ss: "IIS7 is in place."

    it will not work.

    So in my script I create a string command like this:

    $command = "c:\temp\wlogevent.exe -c:41 -l" + [char]58 + $Args[1] + " -ss" +
    [char]58 + [char]34 + $Args[0] + [char]34
    Where $Args[0] and Args[1] are string parameters of a function. I'm using
    [char]58 for the ":" character because I sense there's domething weird about
    colons in powershell.

    Anyway, when I write-host $command, it looks correct in the console output;
    spacing is correct throughout.

    But when I invoke-expression $command, spaces somehow insinuate themselves
    after the colons in the command line, and it doesn't work. I know this by
    viewing the command line of the spawned process, and that command line is

    c:\temp\wlogevent.exe -c: 41 -l: 3 -ss: "IIS7 is in place."

    There is a space after every colon except the one in the path. What is
    going on here?

    Thanks,

    RFV







      My System SpecsSystem Spec

  2.    24 Feb 2009 #2
    DennisD Guest

    Re: Running a command from inside a script, command line is corrupted


    try it like this:

    param (
    $arg1,
    $arg2
    )

    $command = "c:\temp\wlogevent.exe -c:41 -l:$arg1 -ss:`"$arg2`""

    write-host $command


    B.t.w.: "I am trying to give Powershell a chance, since it seems like
    it may have
    some promise." L0L
      My System SpecsSystem Spec

  3.    24 Feb 2009 #3
    Raymond Vought Guest

    Re: Running a command from inside a script, command line is corrupted


    Thank you for responding. I implemented your suggestion so that my function
    looks like this:

    Function InformMe {

    param (

    $arg1,

    $arg2

    )

    $command = "c:\temp\wlogevent.exe -c:41 -l:$arg2 -ss:`"$arg1`""

    write-host $command

    invoke-expression $command

    }

    This works in exactly the same way as my other code; the write-host output
    looks good, but wlogevent.exe breaks because there are spaces in the command
    line after the colons.

    In particular, the write host output in my case looks like this:

    c:\temp\wlogevent.exe -c:41 -l:3 -ss:"IIS7 is in place."

    which is perfect. But the spawned process has command line

    "C:\temp\wlogevent.exe" -c: 41 -l: 3 -ss: "IIS7 is in place."

    (as captured using sysinternals process explorer)

    What is it about colons in powershell?

    RFV






    "DennisD" <dennis.damen@xxxxxx> wrote in message
    news:c502bce8-404b-47ff-9c3f-06cb4f643dbd@xxxxxx

    > try it like this:
    >
    > param (
    > $arg1,
    > $arg2
    > )
    >
    > $command = "c:\temp\wlogevent.exe -c:41 -l:$arg1 -ss:`"$arg2`""
    >
    > write-host $command
    >
    >
    > B.t.w.: "I am trying to give Powershell a chance, since it seems like
    > it may have
    > some promise." L0L

      My System SpecsSystem Spec

  4.    24 Feb 2009 #4
    DennisD Guest

    Re: Running a command from inside a script, command line is corrupted


    I don't think it has anything to do with the colons. Could you try the
    following:

    param (
    $arg1,
    $arg2
    )

    $command = "echo -c:41 -l:$($arg1.trim()) -ss:`"$($arg2.Trim())`""
      My System SpecsSystem Spec

  5.    24 Feb 2009 #5
    Raymond Vought Guest

    Re: Running a command from inside a script, command line is corrupted


    One of the args I am passing is a "3", so can't do .trim() since the "3" has
    been secretly cast as a [System.Int32].

    Using your suggestion, we get error output like this:

    Method invocation failed because [System.Int32] doesn't contain a method
    named
    'trim'.

    Thanks for the suggestion all the same. Tried like this next:

    $command = "c:\temp\wlogevent.exe -c:41 -l:$($arg2) -ss:`"$($arg1.Trim())`""

    This results in the same behavior as before. When we write-host the string
    it looks fine, but when powershell shells this command string, it changes
    the comand string so that where-ever there was "-x:", there's a "-x: ".



    "DennisD" <dennis.damen@xxxxxx> wrote in message
    news:4349673c-731c-49ac-9392-07c2778d5671@xxxxxx

    >I don't think it has anything to do with the colons. Could you try the
    > following:
    >
    > param (
    > $arg1,
    > $arg2
    > )
    >
    > $command = "echo -c:41 -l:$($arg1.trim()) -ss:`"$($arg2.Trim())`""

      My System SpecsSystem Spec


Similar Threads
Thread Forum
Command Prompt doesnt seem to recognize the command line!!
Hello, I'm trying to split a .flv file by using flvparse, which is a Windows-only, command-line interface tool. I did get through to the directory...
Network & Sharing
How to pass the name of a PowerShell script as a command line para
How to pass the name of a PowerShell script as a command line parameter to be run by anther PowerShell script -- or -- How can I call another...
PowerShell
noob: PS script fails, but runs from command line
I want to call RoboCopy from a PS script. When I run this line from the PS command line, it works great: robocopy C:\my\directory...
PowerShell
Call PS Script with Environment Variable in Path via Command Line
Hi, I have a very simple script in my documents that just echos it;s arguments. I.e <user profile>\My Documents\test.ps1--> echo $args I...
PowerShell
Running a Command line script from within powershell.
I have a 3rd party command line tool I need to run from within a powershell script. What is the current method for doing this? I need the calling...
PowerShell
Script from command-line
Ok... I feel as if this worked for me before. From Cmd.exe: powershell "c:\test test\test.ps1" doesn't work. It tells me it doesn't know...
PowerShell
Running PS1 file from command line
Hi, I am trying to run a powershell script from the command line, and I would like this script to NOT show the box that powershell seem to show when...
PowerShell

Our Sites
  • Ten Forums
  • Eight Forums
  • Seven Forums
  • PC Help Forum
  • Help Me Bake
  • Site Links
  • Contact Us
  • Privacy and Cookies
  • About Us
    Windows Vista Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

    Designer Media Ltd
    All times are GMT -5. The time now is 10:40.
    .