我正在尝试从python脚本abc.py执行二进制(my_binary),如下所示。
import os
import sys
import logging
from subprocess import Popen, PIPE
logging.basicConfig(level=logging.DEBUG,format='%(asctime)s %
(levelname)-8s %(message)s',datefmt='%a, %d %b %Y
%H:%M:%S',filename='/var/home/root/root.txt',filemode='w')
os.environ["ABCDE"]="x.x.x.x"
os.environ["USER"]="user"
os.environ["PASSWORD"]="password"
p1 = Popen(["/var/home/root/my_binary","exec"], stdout=PIPE, stderr=PIPE)
out, err=p1.communicate()
logging.info(out)
return out,err
if __name__ == '__main__':
out,err = run(sys.argv[1:])
logging.info(out)
if( out.strip() == "Success: Check:"):
print "Success: OK:"
如果我直接在终端上执行这个abc.py python程序,那么二进制my_binary将被执行。
但是当我尝试从另一个c ++(使用上述类似方式的管道)程序(比如xyz.cpp)运行程序时,my_binary无法执行。
注意:
The xyz.cpp is built with gcc(libstdc++.so.7).
The my_binary is built with gcc(libstdc++.so.6).
my_binary is built with "-D_GLIBCXX_USE_CXX11_ABI=0" as the .so used in
my_binary are built using older g++(v 4.5).
my_binary的ldd o / p
linux-vdso.so.1 => (0x00007fff2c9ff000)
libx.so.0 => /opt/lib/libx.so.0 (0x00007f6caa7f6000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f6caa5d9000)
libstdc++.so.6 => /opt/lib/libstdc++.so.6 (0x00007f6caa4be000)
libm.so.6 => /lib64/libm.so.6 (0x00007f6caa23a000)
libgcc_s.so.1 => /opt/lib/libgcc_s.so.1 (0x00007f6caa224000)
libc.so.6 => /lib64/libc.so.6 (0x00007f6ca9e8f000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f6ca9c8b000)
/lib64/ld-linux-x86-64.so.2 (0x00007f6cab1e0000)
ldd o / p for xyz.cpp
linux-vdso.so.1 => (0x00007fff62dff000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f3b736af000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f3b734ab000)
libz.so.1 => /lib64/libz.so.1 (0x00007f3b72dc2000)
libstdc++.so.7 => /opt/lib64/libstdc++.so.7 (0x00007f3b7204e000)
libm.so.6 => /lib64/libm.so.6 (0x00007f3b71dc9000)
libgcc_s.so.1 => /opt/lib64/libgcc_s.so.1 (0x00007f3b71db2000)
libc.so.6 => /lib64/libc.so.6 (0x00007f3b71a1e000)
/lib64/ld-linux-x86-64.so.2 (0x00007f3b738d2000)
libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f3b70a73000)
objdump -T my_binary | fgrep GLIBC
GLIBCXX_3.4
GLIBC_2.2.5
GLIBC_2.4
objdump -T xyz.cpp | fgrep GLIBC
GLIBC_2.3.2
GLIBC_2.2.5
GLIBCXX_7.0
回溯是:
(gdb) bt
#0 0x00007f80a3f39495 in raise () from /lib64/libc.so.6
#1 0x00007f80a3f3ac75 in abort () from /lib64/libc.so.6
#2 0x00007f80a528a0d5 in __gnu_cxx::__verbose_terminate_handler() ()
from /opt/lib/libstdc++.so.6
#3 0x00007f80a5288166 in ?? () from /opt/lib/libstdc++.so.6
#4 0x00007f80a5288193 in std::terminate() () from
/opt/lib/libstdc++.so.6
#5 0x00007f80a52883e6 in __cxa_throw () from /opt/lib/libstdc++.so.6
#6 0x00007f80a52e3262 in std::__throw_logic_error(char const*) () from
/opt/lib/libstdc++.so.6
#7 0x00007f80a52ef6f1 in char* std::string::_S_construct<char const*>
(char const*, char const*, std::allocator<char> const&,
std::forward_iterator_tag) ()
from /opt/lib/libstdc++.so.6
#8 0x00007f80a52efac8 in std::basic_string<char,
std::char_traits<char>, std::allocator<char> >::basic_string(char
const*, std::allocator<char> const&) ()
from /opt/lib/libstdc++.so.6
所有必需的共享库和静态库都存在于env。
中任何帮助都将不胜感激。
感谢。