Re: send commands to interactive prompt
Re: send commands to interactive prompt
- Subject: Re: send commands to interactive prompt
- From: Kimo Johnson <email@hidden>
- Date: Thu, 29 Jun 2006 09:46:20 -0400
Hi Ruairi,
I've used expect before in cases where I want to completely automate
interactive programs. That's not what I'm looking for here. I want
to send commands to a process already running in Terminal and also
have the ability to switch to the terminal and use the program
(matlab, python) directly. I scanned the wikipedia page you sent but
couldn't tell if expect can be used in this way.
Kimo
On Jun 29, 2006, at 9:37 AM, RuairĂ O' Mahony wrote:
use "expect"
http://en.wikipedia.org/wiki/Expect
-Ruairi
On Jun 29, 2006, at 2:31 PM, Kimo Johnson wrote:
Hi,
I'm looking for a way to send commands to an interactive program
(matlab, python) running in Terminal. I have found 3 partial
solutions, none are exactly what I would like, but all are close.
In TextWrangler, I can highlight text and then hit a keystroke to
run a script on the selected text. I would like to be able to
send this text to a currently running matlab or python session
(ideally without bringing Terminal to the front every time). Here
are the 3 partial solutions:
1) Use Terminal's "do script in window" capability
tell application "Terminal"
do script text_to_execute in window 1
end tell
This works great for sending commands to a shell prompt without
opening a new window each time. If I start an interactive
program, however, the commands are no longer sent to the terminal.
2) Use System Events to type the string
tell application "Terminal"
activate
tell application "System Events"
keystroke text_to_execute
end tell
end tell
This works as well, though I need to bring Terminal to the
front. The problem is that if I assign a keystroke in
TextWrangler to execute this script, the keystroke seems to
interfere with the call to System Events. For example, if the
keystroke to execute the script has "command" in it and the string
I'm trying to send has an "s", Terminal seems to get "command-s."
If I execute the script by clicking the run button, it works fine.
3) Use iTerm instead of Terminal
tell application "iTerm"
tell current session of current terminal
write text text_to_execute
end tell
end tell
This works the best of the three. Actually, it works perfectly
for what I'm trying to do. I would rather not use iTerm though
because of some unrelated bugs that make it not as nice as
Terminal for interactive applications.
So the final question is: can I get the "do script in window"
version (#1) to work if a program is running in the terminal?
Thanks.
Kimo
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (Applescript-
email@hidden)
Help/Unsubscribe/Update your Subscription:
40euro.apple.com
This email sent to email@hidden
--
Regards
RuairĂ O'Mahony
STE Automation
+ 353 (0)21 428 4393
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden