Find the answer to your Linux question:
Results 1 to 2 of 2
Hi, I have two programs (the standard ftp client and a shell script), which I want to make talk one to each other. I.e. ftp's stdout -> script's stdin AND ...
  1. #1
    Just Joined!
    Join Date
    Jan 2009
    Posts
    1

    Bash I/O redirection question

    Hi, I have two programs (the standard ftp client and a shell script), which I want to make talk one to each other. I.e. ftp's stdout -> script's stdin AND reverse - script's stdout to ftp's stdin ... Is it possible to do this with bash?

    I tried pipe + I/O redirection of the stdout of the script to stdin, but it doesn't seem to work.

    I tried things like

    ( exec 5>&0; ( read name; echo "i read $name var" ) | (echo goshko; read b; echo "second script read '$b'") 1>&5 )

    The above code just stucks waiting for input ...

    Any suggestions ?

  2. #2
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    Here's what I got:
    Code:
    alex@danu ~ $ ( exec 5>&0; ( read name; echo "i read $name var" ) | (echo goshko; read b; echo "second script read '$b'") 1>&5 )
    goshko
    *here it waited for input.  I typed the following line and pressed enter.*
    hello
    second script read 'i read hello var'
    Having said that, a saner approach to this would probably be to create a named pipe (called a FIFO, see "man 7 fifo"), and then have the output/input redirected appropriately. This will help clean everything up a bit, I expect.
    DISTRO=Arch
    Registered Linux User #388732

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...