Skip to content Skip to sidebar Skip to footer

Can I Redirect The Output Of This Program To Script?

I'm running a binary that manages a usb device. The binary file, when executed outputs results to a file I specify. Is there any way in python the redirect the output of a binary t

Solution 1:

It looks like you're using Windows, which has a special reserved filename CON which means to use the console (the analog on *nix would be /dev/stdout).

So try this:

subprocess.check_output(r'C:\repos\capture.exe 3 CON 128')

You might need to use shell=True in there, but I suspect you don't.

The idea is to make the program write to the virtual file CON which is actually stdout, then have Python capture that.

An alternative would be CreateNamedPipe(), which will let you create your own filename and read from it, without having an actual file on disk. For more on that, see: createNamedPipe in python

Post a Comment for "Can I Redirect The Output Of This Program To Script?"