Sign in to follow this  
Followers 0
Gameday

How can I escape the & in Send?

5 posts in this topic

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.

Share this post


Link to post
Share on other sites



Try setting the flag to 1 (raw).

Send


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Try setting the flag to 1 (raw).

Send

I tried it, and I still get two 7.

Edited by Gameday

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

<strike>

My previous post is ridiculous. I think it has nothing to do with your question. My mind must've been somewhere else. Sorry 'bout that.

</strike>

Edited by somdcomputerguy

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

Share this post


Link to post
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
Sign in to follow this  
Followers 0