开发者

csh stdin to Python stdin?

开发者 https://www.devze.com 2023-04-01 09:48 出处:网络
How do you redirect the stdin of a csh script开发者_Go百科 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

How do you redirect the stdin of a csh script开发者_Go百科 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!)


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消