Jump to content

How can I escape the & in Send?


Recommended Posts

I am automating a remote command prompt, using Ruby and AutoIt. The AutoIt part looks like this:

$title = $CmdLine[1]
$command = $CmdLine[2]
AutoItSetOption("WinTitleMatchMode", 4)

$firstWindowHandle = WinGetHandle($title)

If $firstWindowHandle Then
    WinActivate($firstWindowHandle)
    ControlSend("","",$firstWindowHandle,$command)
    WinSetState($title,"",@SW_MINIMIZE)
Else
    MsgBox(0,"Error","Cannot find window")
    Exit
EndIf

I compiled the script into an exe, and I'm running it like this:

finder "MyWindow" "dir"

And this will execute dir in that prompt. Locally everything works ok. Remotely, I'm running into a bit of problems when running commands like:

finder "MyWindow" "dir && ls"

As I'm always getting back finder "MyWindow" "dir 77 ls"

How can I make the && be interpreted as a & and not as a 7? I also tried sending the command like dir {ASC 38}{ASC 38} but AutoIt is always transforming it into a 7.

Link to comment
Share on other sites

One more strange thing I noticed. If I run this locally:

$title = "MyWindow"
$command = "dir && ls{ENTER}"

AutoItSetOption("WinTitleMatchMode", 4)

$firstWindowHandle = WinGetHandle($title)

If $firstWindowHandle Then
    WinActivate($firstWindowHandle)
    ControlSend("","",$firstWindowHandle,$command)
    WinSetState($title,"",@SW_MINIMIZE)
Else
    MsgBox(0,"Error","Cannot find window")
    Exit
EndIf

But if I run it on a remote computer, I always get 7's. Is there some option I should be setting AutoIt?

Maybe one more clarification is in order. I have a Ruby client/server, which transports the commands over TCP. The commands are both sent/received correctly by Ruby, I tested. After the ruby client gets the data, it runs this:

system("runner.exe \"#{win_title}\" \"#{command}\"")

Basically, it interpolates the title and the command in a single string, which gets passed to the compiled autoit script. I have no idea what goes wrong. Printing the command line from AutoIt, shows it receives a &, but when it sends, the cmd.exe receives 7.

Edited by Gameday
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...