Skip to content Skip to sidebar Skip to footer

Python Subprocess With Two Inputs

I am a writing a Python program that needs to call an external program, hmm3align, which operates as follows from the command line: hmm3align hmm_file fasta_file -o output_file

Solution 1:

Standard input is a single data stream; on Unix it is a file descriptor connected to the output end of a unidirectional pipe. By convention, programs that read from a single file specified on the command line will understand - as an instruction to read from stdin instead of from a file. However, for a program that reads from two files there is no way to read from stdin twice as it is a single stream of data.

There are other file descriptors that can be used for communication (stdin is fd 0, stdout is fd 1, stderr is fd 2) but there is no conventional way to specify them instead of files.

The solution that is most likely to work here is named pipes (FIFOs); in Python, use os.mkfifo to create a named pipe and os.unlink to delete it. You can then pass its name to the program (it will appear as a file that can be read from) while writing to it (using open).

Post a Comment for "Python Subprocess With Two Inputs"