How to return spawned process exit code in Expect script?
Date : March 29 2020, 07:55 AM
Hope this helps You're already waiting for the eof at the end of your loop, you just need to use wait and catch the result: spawn true
expect eof
catch wait result
exit [lindex $result 3]
spawn false
expect eof
catch wait result
exit [lindex $result 3]
|
How to get the exit code of spawned process in expect shell script?
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further With the help of glenn, I got solution.. and my final script is:: expect script is [Linux Dev:anr ]$ cat testexit.sh
#!/bin/bash
export tmp_script_file="/home/anr/tmp_script_temp.sh"
cp /home/anr/tmp_script $tmp_script_file
chmod a+x $tmp_script_file
cat $tmp_script_file
expect << 'EOF'
set timeout -1
spawn $env(tmp_script_file)
expect {
"INVALID " { exit 4 }
timeout { exit 4 }
eof
}
foreach {pid spawnid os_error_flag value} [wait] break
if {$os_error_flag == 0} {
puts "exit status: $value"
exit $value
} else {
puts "errno: $value"
exit $value
}
EOF
echo "spawned process status" $?
rm -f $tmp_script_file
echo "done"
[Linux Dev:anr ]$ cat tmp_script
exit 3
[Linux Dev:anr ]$ ./testexit.sh
exit 3
spawn /home/anr/tmp_script_temp.sh
exit status: 3
spawned process status 3
done
|
TCL/Expect equivalent of Bash $@ or how to pass arguments to spawned process in TCL/Expect
Tag : bash , By : dexteryy
Date : March 29 2020, 07:55 AM
help you fix your problem If somebody wants to call external program (which was passed as a Bash argument) from Bash and also pass it command line options (which were also passed as a Bash arguments) the solution is fairy simple: , To literally translate your example set program [lindex $argv 0]
set arguments [lrange $argv 1 end]
spawn $program {*}$arguments
spawn [lindex $argv 0] [lrange $argv 1 end]
spawn [lindex $argv 0] {*}[lrange $argv 1 end]
proc lshift {varname} {
upvar 1 $varname var
set var [lassign $var first]
return $first
}
expect1.6> set argv {foo bar baz}
foo bar baz
expect1.7> set script [lshift argv]
foo
expect1.8> set script
foo
expect1.9> set argv
bar baz
|
need to return exit code of spawned procees from expect script
Tag : shell , By : KingGuppy
Date : March 29 2020, 07:55 AM
|
Expect spawned snx process dies
Date : March 29 2020, 07:55 AM
|