0

I have a program running on linux

This program take its input from the stdin

So I can launch it with input file in this way

myprogram < file

in order to avoid typing input to the program

Now I want that the program take the input from a command output. something like that

myprogram < anycommand

but this does not work because it's expecting a file and not a command.

How I can make it work? Are there a shell syntax to make it work?

Note: I can not use pipe like anycommand | myprogram

1
  • 2
    Best to explain why can't you use anycmd| myprog? That is a core pattern of all Unix-like programs. Good luck. Commented Apr 29, 2014 at 11:44

3 Answers 3

3

normally (IMHO) myprogram does not know anything about file. The bash starts myprogram and reads the file, and writes the content of file to the stdin of myprogram. So myprogram should not know that his stdin is a file. So, anycommand | myprogram must work.

If it doesn't work with ash, maybe you can make a named pipe (mkfifo /tmp/testpipe) Now you can start your program with myprogram < /tmp/testpipe and you can write your input to /tmp/testpipe

Sign up to request clarification or add additional context in comments.

Comments

2

On my Linux system, ash is a symbolic link to dash and that handles pipes just fine:

pax> ls -ld $(which ash)
lrwxrwxrwx 1 root root 4 Mar  1  2012 /bin/ash -> dash

pax> ash

$ echo hello | tr '[a-z]' '[A-Z]'
HELLO

So I'd give the anycommand | myprogram another shot just in case.

If your ash has no piping capability, you can always revert to using temporary files, provided anycommand isn't a long-lived process that you need to handle the output of in an incremental fashion:

anycommand >/tmp/tempfile
myprogram </tmp/tempfile

Comments

0

You need to use it like this:

myprogram < <(anycommand)

This is called process substitution

4 Comments

thanks for the answer. I tried your command but it returns the following error: -ash: syntax error: unexpected redirection
I am not sure if ash supports this, can you use bash?
I don't have a way to test it in ash since I don't have it. Is there any online tester for this?
I looked at linux.about.com/library/cmd/blcmdl1_ash.htm and didn't find any process substitution. Did you try: anycommand|myprogram? What error you got?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.