Pipe string with quotes and double quotes inside

Hello,
Sorry if this question is not directly related to Arduino,
I'm trying to pipe a BMP file through a fifo in an Android phone like this (using python):

image_file = Image.open(f"{path}{input_file}")
image_file = image_file.convert('1') # convert image to black and white

output = io.BytesIO()
image_file.save(output, format='BMP')
byte_string = output.getvalue() 

md1 = 'adb shell'
cmd2 = 'run-as com.example.pipe' #to access the phone's app directory 
cmd3 = f"echo "
cmd4 = " > thepipe"
fin = byte_string

p = subprocess.Popen(cmd1.split(), stdin=PIPE)
p.stdin.write(cmd2.encode('utf-8'))
p.stdin.write('\n'.encode('utf-8'))
p.stdin.write(cmd3.encode('utf-8'))
p.stdin.write(byte_string)
p.stdin.write(cmd4.encode('utf-8'))
p.stdin.write('\n'.encode('utf-8'))
p.stdin.flush()
p.kill()

It works the problem is that byte_string contains random quotes and double quotes that mess the transfer. How can i specify the start and end of byte_string? thanks

In C++ you escape quotations in strings using the backslash character

 Serial.println("Hello \"New\" World");

prints

Hello "New" World

Presumably Python has a similar facility