2

How do you redirect the stdin of a csh script to the stdin of a python script?

I have a cgi script I'm writing in csh that runs on a Solaris machine. This csh script is a wrapper to a python script that reads from the stdin (I know, scripting in csh is bad but I'm forced to in this case).

Thanks for help! (And sorry for the n00b question!)

RaytheonLiszt
  • 225
  • 1
  • 6
  • 15

2 Answers2

6

test.csh

#!/bin/env csh
python test.py

test.py (see this question)

#!/bin/env python
import fileinput

if __name__ == '__main__':
    print "Hi. printing stdin"
    for line in fileinput.input():
        print line

    print "fin"

Then the stdin to test.csh is passed in to test.py as Henning said.

echo "this is stdin" | csh test.csh
Community
  • 1
  • 1
Pete
  • 10,310
  • 7
  • 53
  • 59
3

You don't need to do anything. Commands (such that a Python script) that you start from a shell (such as csh) will inherit the shell's stdin (and stdout, stderr) by default unless you actively do something to prevent it.

hmakholm left over Monica
  • 23,074
  • 3
  • 51
  • 73