Can process substitution be used as an input file to another program?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Can process substitution be used as an input file to another program?
# 1  
Old 06-22-2009
Can process substitution be used as an input file to another program?

Hey, I was trying to figure out how to launch a program from the command line, and it works if you pass it a config file. I was thinking about writing a script to dynamically create the config file and pass it to the command using something like command substitution (so I don't actually have to create a file).

I'm using Bash 3.2.39

Well I went and tried the following just to see if it would work:
Code:
command --config <(cat ./configfile)

But it just said that it can't find the file /dev/fd/63.

Well
Code:
cat <(cat ./configfile)

does work (dumps it to the screen), so I thought maybe the file descriptor was being closed before the commad could use it.

So I tried making a more persistent one:
Code:
exec 10< <(cat ./configfile)
command --config /dev/fd/10

But it just says that it cannot find /dev/fd/10, even though it is there, and i can
Code:
cat /dev/fd/10

just fine (albeit just once).

Shouldn't this be possible? Or does the program have to do something special to be compatable with named pipes?

I'm not super-knowledgable about bash, but I've read as much as I can find on the subject. Any insight is appreciated!

Thanks.
# 2  
Old 06-23-2009
Um, I won't get into the technicalities of why you tried didn't work -- it's a bit complicated. Normally you want to send input from a file like this:
Code:
command < configfile

You can do this with named pipes:
Code:
mkfifo /var/tmp/mypipe.$$
cat configfile > /var/tmp/mypipe.$$ &
command --config /var/tmp/mypipe.$$

You have to put the cat into the background, because the pipe doesn't buffer any input.
# 3  
Old 06-23-2009
While not as simple as I had hoped, it certainly does work.

I also found that using the Zsh shell, you can force process substitution to automatically use a temporary file instead of a pipe with =().

So:
Code:
command --config =( cat configfile )

works, but not in Bash.
# 4  
Old 06-24-2009
Hey, that rocks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem with process substitution

i have tried process substitution, but run in some problems. this works: samtools view -h $SAMdir/$b.bam | htseq-count -m union -s no -q -t exon -i gene_id - $gtf > $b.count & but this not: htseq-count -m union -s no -q -t exon -i gene_id <(samtools view -h $SAMdir/$b.bam) $gtf >... (7 Replies)
Discussion started by: dietmar13
7 Replies

2. Shell Programming and Scripting

How to give a text file as input while running a program?

Hi Friends, I am running a program /path/to/program -i 1 100 -o /path/to/output/op_1_100.txt In the above command, I have to try various number of combinations at the -i parameter and the output file name varies with each combination. Now, I have my -i parameter text file, which is like... (4 Replies)
Discussion started by: jacobs.smith
4 Replies

3. UNIX for Dummies Questions & Answers

Process Substitution Question?

Hello to all. I'm new to this forum, so please go easy on me. =) I am working on a script to send two e-mail attachments in a single e-mail, and am running into a little bit of an issue when using process substitution. I am using the following: cat <(uuencode $1 <(basename $1)) <(uuencode... (5 Replies)
Discussion started by: rommager
5 Replies

4. Shell Programming and Scripting

Help to write a script or program to automatic execute and link input file data

Output file template format <input_file_name>a</input_file_name> <total_length_size>b</total_length_size> <log_10_length_size>c</log_10_length_size> Input_file_1 (eg. sample.txt) SDFSDGDGSFGRTREREYWW Parameter: a is equal to the input file name b is equal to the total length of... (2 Replies)
Discussion started by: perl_beginner
2 Replies

5. UNIX for Advanced & Expert Users

Help with command substitution in C program

Hi, I want to know if there's a cleaner way for assigning output of a unix command to a variable in C program . Example : I execute dirname fname and want the output to be assigned to a variable dname . Is it possible . I knew u can redirect the output to a file and then reread assigning... (5 Replies)
Discussion started by: royalbull
5 Replies

6. Shell Programming and Scripting

How to make AWK process an input file many many times?

By "many many times" I mean the times the input file is to be processed is unknown beforehand, it will be known when awk finishes processing the input file for the first time. So my question is: how to start over again from the first record of the input file when AWK finishes processing the... (7 Replies)
Discussion started by: kevintse
7 Replies

7. Shell Programming and Scripting

How to read the input from a file in background process?

Hi I have a script to run some other scripts automatically. But while running the script it should take the input value from a text file instead of taking from the keyboard. Please find last two lines of the script below. Here ans should be taken from a text file ineerly without displaying this... (1 Reply)
Discussion started by: shirdi
1 Replies

8. Shell Programming and Scripting

Process substitution

Just playing around with process substitution. Hoping maybe someone can give me some help on what I'm doing wrong. When this script is run, "Null message body; hope that's ok" is returned and the script hangs. I can't seem to work out what I'm doing wrong. Here is the script: #!/bin/bash... (3 Replies)
Discussion started by: mandelbrot333
3 Replies

9. Shell Programming and Scripting

How to run this program with only one input file at a time

i have a program ABC, which runs every two minutes and takes the input according to the a value called "pointer" files need to be processed by ABC are input0001 input0002 input0003 input0004 input0005 current value of pointer is 0001, now program runs and takes all the files from... (2 Replies)
Discussion started by: Prat007
2 Replies

10. Shell Programming and Scripting

File path with space as external input to the program

Hello I am getting error when the file (Folder or Application) path having space is given as external input to the shell program. It works fine for the files which has no spaces in the file name Thans, (5 Replies)
Discussion started by: keshav.murthy@r
5 Replies
Login or Register to Ask a Question