Windows Vista Forums

invoke-expression problem
  1. #1


    Jacques Guest

    invoke-expression problem

    People

    I'm having a problem making a string from a number of variables (I've
    simplified the stuff below) then executing it, and have tried a number of
    permutations but can't make it work.



    First, double-quoting:
    $command="isql -Uuser -Ppassword -SSERVER-i`"C:`\temp`\tmpLoadTran.sql`""
    $command
    isql -Uuser -Ppassword -SSERVER-i"C:\temp\tmpLoadTran.sql"
    invoke-expression $command
    Invoke-Expression : Incomplete string token.
    At line:1 char:18
    + invoke-expression <<<< $command

    Next, single-quoting
    $command='isql -Uuser -Ppassword -SSERVER-i"C:\temp\tmpLoadTran.sql"'
    $command
    isql -Uuser -Ppassword -SSERVER-i"C:\temp\tmpLoadTran.sql"
    invoke-expression $command
    Invoke-Expression : Incomplete string token.
    At line:1 char:18
    + invoke-expression <<<< $command

    Then, reduce the path and double-quote:
    isql -Uuser -Ppassword -SSERVER-i"tmpLoadTran.sql"
    invoke-expression $command
    Invoke-Expression : Incomplete string token.
    At line:1 char:18
    + invoke-expression <<<< $command

    Then, reduced path and single quotes:
    $command='isql -Uuser -Ppassword -SSERVER-i"tmpLoadTran.sql"'
    $command
    isql -Uuser -Ppassword -SSERVER-i"tmpLoadTran.sql"
    invoke-expression $command
    Invoke-Expression : Incomplete string token.
    At line:1 char:18

    Finally, reduced path, single quotes and no suffix:
    $command='isql -Uuser -Ppassword -SSERVER-i"tmpLoadTran"'
    $command
    isql -Uuser -Ppassword -SSERVER-i"tmpLoadTran"
    invoke-expression $command
    Unable to open input file 'tmpLoadTran'.

    Finally, that 'Unable to open~~~' is from Sybase.

    What do I need to do to my expression including the path and the suffix so
    that invoke-expression runs it? Or can I not use invoke expression like
    this? Are there any alternatives?

    Thanks in advance for any clues or ideas.

    Jacques



      My System SpecsSystem Spec

  2. #2


    Marco Shaw [MVP] Guest

    Re: invoke-expression problem


    > What do I need to do to my expression including the path and the suffix so
    > that invoke-expression runs it? Or can I not use invoke expression like
    > this? Are there any alternatives?
    >
    > Thanks in advance for any clues or ideas.
    >
    > Jacques
    >
    One more to try:

    $command="isql `-Uuser `-Ppassword `-SSERVER `-i`"C:\temp\tmpLoadTran.sql`""

    Let us know if that works for you.

    Marco

    --
    Microsoft MVP - Windows PowerShell
    http://www.microsoft.com/mvp

    PowerGadgets MVP
    http://www.powergadgets.com/mvp

    Blog:
    http://marcoshaw.blogspot.com

      My System SpecsSystem Spec

  3. #3


    Shay Levi Guest

    Re: invoke-expression problem


    Doe's this work?

    $isqlArgs="-Uuser -Ppassword -SSERVER -i""C:\temp\tmpLoadTran.sql"""
    & isql $isqlArgs


    ---
    Shay Levi
    $cript Fanatic
    http://scriptolog.blogspot.com

    > People
    >
    > I'm having a problem making a string from a number of variables (I've
    > simplified the stuff below) then executing it, and have tried a
    > number of permutations but can't make it work.
    >
    > First, double-quoting:
    > $command="isql -Uuser -Ppassword
    > -SSERVER-i`"C:`\temp`\tmpLoadTran.sql`""
    > $command
    > isql -Uuser -Ppassword -SSERVER-i"C:\temp\tmpLoadTran.sql"
    > invoke-expression $command
    > Invoke-Expression : Incomplete string token.
    > At line:1 char:18
    > + invoke-expression <<<< $command
    > Next, single-quoting
    > $command='isql -Uuser -Ppassword -SSERVER-i"C:\temp\tmpLoadTran.sql"'
    > $command
    > isql -Uuser -Ppassword -SSERVER-i"C:\temp\tmpLoadTran.sql"
    > invoke-expression $command
    > Invoke-Expression : Incomplete string token.
    > At line:1 char:18
    > + invoke-expression <<<< $command
    > Then, reduce the path and double-quote:
    > isql -Uuser -Ppassword -SSERVER-i"tmpLoadTran.sql"
    > invoke-expression $command
    > Invoke-Expression : Incomplete string token.
    > At line:1 char:18
    > + invoke-expression <<<< $command
    > Then, reduced path and single quotes:
    > $command='isql -Uuser -Ppassword -SSERVER-i"tmpLoadTran.sql"'
    > $command
    > isql -Uuser -Ppassword -SSERVER-i"tmpLoadTran.sql"
    > invoke-expression $command
    > Invoke-Expression : Incomplete string token.
    > At line:1 char:18
    > Finally, reduced path, single quotes and no suffix:
    > $command='isql -Uuser -Ppassword -SSERVER-i"tmpLoadTran"'
    > $command
    > isql -Uuser -Ppassword -SSERVER-i"tmpLoadTran"
    > invoke-expression $command
    > Unable to open input file 'tmpLoadTran'.
    > Finally, that 'Unable to open~~~' is from Sybase.
    >
    > What do I need to do to my expression including the path and the
    > suffix so that invoke-expression runs it? Or can I not use invoke
    > expression like this? Are there any alternatives?
    >
    > Thanks in advance for any clues or ideas.
    >
    > Jacques
    >


      My System SpecsSystem Spec

invoke-expression problem problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with invoke-expression Ben Christian PowerShell 4 06 Apr 2008
Invoke-Expression issue RG PowerShell 4 14 Jan 2008
Invoke-expression vs & Leo Tohill PowerShell 4 29 Nov 2007
invoke-expression not appending Frank PowerShell 3 30 Jun 2007
Issue: Invoke-Expression with $args in the expression =?Utf-8?B?Um9tYW4gS3V6bWlu?= PowerShell 1 22 Sep 2006