#!/usr/bin/expect -f set timeout 20 # Set PS1 so that we have a consistent value to 'expect', # since the default PS1 differs between platforms. set ::env(PS1) "sh$" spawn /bin/sh set executable [lindex $argv 0]; set output_path [lindex $argv 1]; set contents [lindex $argv 2]; expect "sh" send -- "$executable \$(tty) $output_path\r" expect "$executable" send -- "$contents\x04\x04" expect "sh" send -- "exit\r" expect eof