I coded a simple asm binary file that get the arg of the user and then prints it on the screen using the C func printf.
So the code is compile using:
nasm -f elf64 ...
gcc -m64 -no-pie ....
The program works very well. I want to use it with python and doing so, i can launch it with subprocess.Popen(cmd) (this works well too)
Buuuut when i want to capture the output of my asm compiled program in order to parse it with python, the output is always empty ...
I tried:
subprocess.Popen(cmd, stdout=PIPE, stderr=PIPE)
subprocess.call(...)
subprocess.run(...)
subprocess.check_output(...)
os.system(...)
os.popen(...)
Anyway i think i tested all the ways ... I really don't understand why the program works well on my python script except if i try to capture the output.
If someone have an idea ...., please let me know.
The asm code is:
; nasm -f elf64 -o test.o test.asm
; gcc -m elf64 test.o -o test
extern printf
section .text
global main
main:
mov rdi, fmt
mov rsi, s_val
xor rax, rax
call printf WRT ..plt
; exit
xor rdi, rdi,
mov rax, 0x3c
syscall
section .data
s_val db 'hello world', 0
fmt db '%s',0x0a, 0
The python code is:
#!/usr/bin/python3
import subprocess
from subprocess import Popen
p = Popen(['/home/test'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
r = p.communicate()
print(r)
thx