[lxc-users] What's the best way to get stderr from lxc-attach when running a command?

Fajar A. Nugraha list at fajar.net
Wed Feb 18 08:42:13 UTC 2015


On Wed, Feb 18, 2015 at 3:33 PM, Dan Shi <bruingo at gmail.com> wrote:
> I'm trying to run some command in container through lxc-attach. The script
> is in python 2.7. Apparently, command like following does not raise a
> subprocess exception:
> subprocess.check_output('lxc-attach -n c1 -- ls non_exist_dir')
>
> One way to get the stderr from the ls command running in container could be
> using -o option to direct the stderr to a local log file, then parse the log
> file to see any errors. It's not really a clean solution. I'm wondering if
> there is a better way to do this?

Are you sure this is not python issue? Shell redirection seems to work fine

# lxc-attach -n template -- ls -la /blah 2>/tmp/err;echo $?
2

# cat /tmp/err
ls: cannot access /blah: No such file or directory

-- 
Fajar


More information about the lxc-users mailing list