-1

Using Chrome Native Messaging sample app as a template am able make a system call to bash

os.system("<bash command>")

The requirement is to return a base64 string from the python script

os.system("<bash command that returns a base64 string>")

which can verify returns expected result at terminal.

However, when adjust the code at native-messaging-example-host at lines 97-98 to

dataurl = os.system("<bash command that returns a base64 string>")
text = '{"text": "' + dataurl + '"}'

the application window closes and

Failed to connect: Error when communicating with the native messaging host.

is printed at the applications' HTML page.

When using the original code

text = '{"text": "' + self.messageContent.get() + '"}' 

and sending the base64 string corresponding to the output that the bash command outputs to the python host, the base64 is sent back to the client. The length of the tested base64 string is 43304, less than the 1 MB maximum size of messages sent from the host.

Why is the application throwing an error and not sending the base64 string from the python host to the Chromium client?

guest271314
  • 1
  • 15
  • 104
  • 177

1 Answers1

0
import supprocess as sub
ter = sub.Popen("<bash command that returns a base64 string>",
                          shell=True,stdout=sub.PIPE)
tread = cmd.communicate()[0].decode("u8")
text = '{"text": "' + tread + '"}'

Try This ^_^

Alaa Aqeel
  • 615
  • 8
  • 16
  • Tried the code substituting `subprocess` for `supprocess` though the string is not sent to client. The string sent to host is echoed. – guest271314 Jan 20 '18 at 06:30