5

Similar problem as here How to redirect output from file to stdout? However, the solution given there is not universal.

My problem: I have a command that produces output to STDOUT. At the same time, I can specify via arguments to produce another output that goes straight to a file.

tcsh$ hmmscan --domtblout FILEOUTPUT Pfam-A.hmm query.fasta

Pfam-A.hmm is a database file (input); query.fasta is also an input file

How can I redirect FILEOUTPUT to STDOUT ?

Background: I plan to use the command on thousands of inputs and I need to run it for each of them separately. The command is called within a Python script, and I would like to read its FILEOUTPUT directly into the memory/a variable using the subprocess module. I know how to get the STDOUT with the subprocess module; so if I could redirect FILEOUTPUT to STDOUT...

I tried already stuff like this (ended up with errors or created files):

tcsh$ hmmscan --domtblout >/dev/tty Pfam-A.hmm query.fasta
tcsh$ hmmscan --domtblout >(mypipe) Pfam-A.hmm query.fasta
tcsh$ hmmscan --domtblout >$ Pfam-A.hmm query.fasta
tcsh$ hmmscan --domtblout >($1) Pfam-A.hmm query.fasta
tcsh$ hmmscan --domtblout >cat Pfam-A.hmm query.fasta
tcsh$ hmmscan --domtblout test.tab Pfam-A.hmm query.fasta >/dev/tty
1
  • 1
    there's a tcsh in your prompt string; does the solution need to work in tcsh, or were those just sample runs, while your code would be called from python (to /bin/sh, presumably)?
    – Jeff Schaller
    Oct 23, 2018 at 0:12

1 Answer 1

3

To make the hmmscan program write to stdout instead of a regular file, specify /dev/stdout instead of the regular filename. e.g.

$ hmmscan --domtblout /dev/stdout Pfam-A.hmm query.fasta

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .