2011-08-29 170 views
2

如何将csh脚本的stdin重定向到python脚本的stdin?csh标准输入到Python标准输入?

我有一个cgi脚本,我正在写一个Solaris机器上运行的csh。这个csh脚本是从stdin读取的python脚本的包装器(我知道,csh中的脚本很糟糕,但我在这种情况下被迫使用)。

感谢您的帮助! (对于n00b问题抱歉!)

回答

6

test.csh

#!/bin/env csh 
python test.py 

test.py(见this question

#!/bin/env python 
import fileinput 

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

    print "fin" 

然后,标准输入到test.cshtest.pyas Henning said传递。

echo "this is stdin" | csh test.csh 
+0

完美!非常感谢!! – RaytheonLiszt

3

你不需要做任何事情。 从shell(例如csh)开始的命令(例如Python脚本)将默认继承shell的stdin(和stdout,stderr),除非您主动执行某些操作来阻止它。

+0

太简单了!我希望我可以将2个答案标记为解决方案。感谢您的解释!!!! – RaytheonLiszt

+0

哦,好的。无论如何,我已经为我制定了配额:-) –