I am trying to capture the exit status of wget or fetch command. The way I try to capture it is the following way. First I connect to the virtual machine -
child = pexpect.spawn('virsh --connect qemu:///system console {} --force'.format(quote(pfsense_domain)), timeout=200, maxread=400, encoding='utf-8')
and then I run some commands and finally I try to download configuration file from a server. I tried doing it with fetch and wget, but I am unable to capture the exit status. Here is how I do the fetch/wget command -
child.send("fetch {} -o {} >/dev/null ; echo $?".format(quote(repo), quote(TMP_CONFIG)))
child.send("wget -c {} -O {} >/dev/null ; echo $?".format(quote(repo), quote(TMP_CONFIG)))
I tried capturing the output multiple ways but I am unable to extract the correct response. If for example I try to get exit code 8, the pexpect will return 0. They way I capture is like this:
child.logfile = sys.stdout
index = child.expect_exact(["1", "0", "8"])
child.expect("8")
However when I connect to the device I see that the command has returned the correct exit code. I tried doing it manually and it returns the correct code. It seems like there is something wrong with pexpect when running it on FreeBSD software. Any tips how to capture the correct exit code? It works fine on Ubuntu! Any help will be appreciated!