Invoke-Expression to run GDB on remote vm

This topic contains 0 replies, has 1 voice, and was last updated by Profile photo of Forums Archives Forums Archives 5 years, 6 months ago.

  • Author
    Posts
  • #5837

    by Davehal at 2013-04-23 04:18:28

    Hi,

    I'm very new to PowerShell and this is a kind of specialised question, so if I'm asking in the wrong place, please let me know.
    I'm writing a PowerShell script which sends commands to a remote virtual machine which is running linux.
    I am using plink which is just a ssh client to connect to the vm, this connects no problem and I can run simple commands no problem. My issue appears when I try to send commands that run an application on the vm called GDB. This is the Gnome Debugger.
    I dont think my problem is related to plink, gdb or linux, I think it is how I am executing the PowerShell command.
    My problem is that when I run the command to execute the debugger "./rungdb", it runs fine, but my PowerShell script never completes, it just sits there after the Invoke-Expression command and never moves on.

    The code is below, can anyone tell me how to get it to complete the Invoke-Expression statement and move on?

    Thank you, and sorry if this doesn't make sense!

    write-host "Host login attempt..`n";
    $HostAddress = '10.10.10.10';

    if($HostAddress -notlike "")
    {
    $myExpression = "& " + $plink + " -pw password -ssh root@" + $HostAddress + " ./rungdb";
    Invoke-Expression $myExpression;
    }

    by DexterPOSH at 2013-04-23 06:47:53

    [quote="Davehal"] $myExpression = "& " + $plink + " -pw password -ssh root@" + $HostAddress + " ./rungdb";[/quote]

    Hi Davehal,

    I think the problem is with the expression you are building "&" is a call operator in PowerShell, it essentially does what Invoke-Expression is doing for you here.
    Try removing the "&" and then run the script from the above line. I am also doubtful about how you are building the expression.

    Try this link to see better ways to call executables in Windows PowerShell http://social.technet.microsoft.com/wiki/contents/articles/7703.powershell-running-executables.aspx

    Hope this helps
    ~Dexter~

    by happysysadm at 2013-04-23 07:09:47

    Dexter is right, you are misusing '&'.

    First I suggest you store your parameters to the linux VM in a putty names session, so you don't have to leave your password in clear in your script.

    Then run something like this:

    [code2=powershell]$command = & .\plink.exe hostname -load sessionname "whatever command"[/code2]

    Carlo

You must be logged in to reply to this topic.