Re: expect - problem split argv 0, then send each item as command



On Apr 20, 7:23 am, inetquestion <inetquest...@xxxxxxxxxxx> wrote:
When I execute the following script via: ./go.exp
"date;hostname;uname"
I only get output from the puts line, instead of actually sending the
commands to a shell. What am I missing? Is there a problem putting an
expect block inside a foreach loop?

-Inet

#!/usr/bin/expect

foreach element [ split [lindex $argv 0] ";" ] {
puts "sending: $element\n"
expect {
-re ".*$" { send -- "$element\r" }
}

}

-------
-------

./go.exp "date;hostname;uname"
sending: date

sending: hostname

sending: uname

You need to do [ spawn /bin/bash ] first. Expect has to talk to a
process, you cannot just send commands from Expect to Expect, it
doesn't know where you want to send it.

As I mentioned it before in this group, do use autoexpect, you would
have seen that right away in it's output script.

---Victor
.



Relevant Pages

  • find-name-dired and find-dired fail on windows/cygwin
    ... I am trying to find (say a *.cpp) file using either one of the ... find: missing argument to `-exec' ... This commands start to work but then I have igrep-find failing with ... I am quite confused if I should make bash a default shell, ...
    (comp.emacs)
  • expect - problem split argv 0, then send each item as command
    ... When I execute the following script via: ... I only get output from the puts line, ... commands to a shell. ...
    (comp.lang.tcl)
  • Re: Redirection issue
    ... 1- execute input commands from standard input, ... code to implement the redirection it does not work anymore. ... And it's not good shell behavior to echo commands anyway. ...
    (comp.lang.c)
  • Re: Redirection issue
    ... 1- execute input commands from standard input, ... the phrase "it does not work anymore" carries very little meaning. ... after compilation and execution of the shell with a simple command like ...
    (comp.lang.c)
  • vulnerabilities in scponly
    ... without allowing shell access. ... scponly makes no effort to verify the path to the scp or sftp-server ... arbitrary commands by simply uploading a file. ... However, if this is *NOT* the case, the user could execute arbitrary ...
    (Bugtraq)