如何将csh脚本的stdin重定向到python脚本的stdin?
我有一个cgi脚本,我正在用在Solaris机器上运行的csh编写.这个csh脚本是从stdin读取的python脚本的包装器(我知道,在csh中编写脚本很糟糕但在这种情况下我不得不这样做).
感谢帮助!(抱歉n00b问题!)
对于如何读取标准输入,我们有这个很好的答案.
stdin?print像stdout?我问它因为我在facebook演示拼图中看到了这个订单:
注意:您需要编写完整代码,所有输入都来自stdin和输出到stdout如果您使用的是"Java",则类名为"Solution"
我正在将一些主要的十六进制输入读取到 Python3 脚本中。但是,系统设置为使用UTF-8,当从 Bash shell 管道传输到脚本时,我不断收到以下UnicodeDecodeError 错误:
UnicodeDecodeError: ('utf-8' codec can't decode byte 0xed in position 0: invalid continuation byte)
sys.stdin.read()根据其他 SO 答案,我在 Python3 中使用来读取管道输入,如下所示:
import sys
...
isPipe = 0
if not sys.stdin.isatty() :
isPipe = 1
try:
inpipe = sys.stdin.read().strip()
except UnicodeDecodeError as e:
err_unicode(e)
...
Run Code Online (Sandbox Code Playgroud)
它在使用这种方式管道时起作用:
# echo "\xed\xff\xff\x0b\x04\x00\xa0\xe1" | some.py
<output all ok!>
Run Code Online (Sandbox Code Playgroud)
但是,使用原始格式不会:
# echo -en "\xed\xff\xff\x0b\x04\x00\xa0\xe1"
???
??
# echo -en "\xed\xff\xff\x0b\x04\x00\xa0\xe1" | some.py
UnicodeDecodeError: ('utf-8' codec can't decode …Run Code Online (Sandbox Code Playgroud) <<<在这个命令行中意味着什么?
bc <<< "1 + 1"
Run Code Online (Sandbox Code Playgroud)
它似乎并不组合<和<<,我不能为它找到文档.它似乎表现得像
echo "1 + 1" | bc
Run Code Online (Sandbox Code Playgroud)
也适用于ksh,但不在sh.
type=argparse.FileType()我可以通过将 argparse 更改为某些 gzip 类型来直接使用 argparse 打开 gzip 文件吗?它不在文档中,所以我不确定 argparse 是否支持压缩文件类型......
我正在尝试解决 SPOJ 的问题。为此,我需要能够从 stdin 读取输入,我使用 scanf 在 C 中遇到了很多问题,但也想尝试使用 Python。如何读取 Python 中的 stdin 输入?(想使用Python 2.6/2.7)