本文整理汇总了Python中subprocess.Popen.stdin方法的典型用法代码示例。如果您正苦于以下问题:Python Popen.stdin方法的具体用法?Python Popen.stdin怎么用?Python Popen.stdin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类subprocess.Popen
的用法示例。
在下文中一共展示了Popen.stdin方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import stdin [as 别名]
def main (filepath):
# abort if it is directory
if os.path.isdir(filepath):
sys.exit("azcat: '%s' is a directory. Aborted." % filepath)
try:
with open(filepath, "r") as f:
s = f.read()
except IOError as e:
sys.exit("azcat: cannot open '%s': %s" % (f, str(e)))
except UnicodeDecodeError:
sys.exit("azcat: file seems a binary file. Aborted.")
if s.find("\x00") != -1:
sys.exit("azcat: file seems a binary file. Aborted.")
# confirm if file size is larger than 1MB
if os.path.getsize(filepath) > 1024*1024:
if input("file size is big; do you continue? [Y/n]: ") == "n":
sys.exit("aborted.")
# if the number of lines is over 50, pipe to a pager
if s.count("\n") > 50:
p = Popen(["less", "-R", "-"], stdin=PIPE)
try:
out = p.stdin
pretty_print(filepath, out)
p.stdin = sys.stdin
p.wait()
except IOError: # this will raised after the pager existed
pass
else:
out = sys.stdout.buffer
pretty_print(filepath, out)
示例2: main
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import stdin [as 别名]
def main (args):
s = load_file(args["file"])
# if the number of lines is over 50, pipe to a pager
if s.count("\n") > 50:
p = Popen(["less", "-R", "-"], stdin=PIPE)
try:
pretty_print(args["file"], s, p.stdin, args["with_formatter"])
p.stdin = sys.stdin
p.wait()
except IOError: # this will raised after the pager existed
pass
else:
out = sys.stdout.buffer
pretty_print(args["file"], s, out, args["with_formatter"])
示例3: nopen_keep_parent_stdin
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import stdin [as 别名]
def nopen_keep_parent_stdin(f, mode="r"):
if f.startswith("|"):
# using shell explicitly makes things like process substitution work:
# http://stackoverflow.com/questions/7407667/python-subprocess-subshells-and-redirection
# use sys.stderr so we dont have to worry about checking it...
p = Popen(f[1:], stdout=PIPE, stdin=sys.stdin,
stderr=sys.stderr if mode == "r" else PIPE,
shell=True, bufsize=-1, # use system default for buffering
preexec_fn=toolshed.files.prefunc,
close_fds=False, executable=os.environ.get('SHELL'))
if sys.version_info[0] > 2:
import io
p.stdout = io.TextIOWrapper(p.stdout)
p.stdin = io.TextIOWrapper(sys.stdin)
if mode != "r":
p.stderr = io.TextIOWrapper(p.stderr)
if mode and mode[0] == "r":
return toolshed.files.process_iter(p, f[1:])
return p
else:
return toolshed.files.nopen(f,mode)
示例4: bwamips
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import stdin [as 别名]
def bwamips(fastqs, ref_fasta, mips, num_cores, umi_length, picard):
tmp_sam_name = mktemp(suffix=".sam.gz")
name = get_base_name(*fastqs)
sam_gz = bwa_mem(fastqs, name, ref_fasta, tmp_sam_name, num_cores, umi_length)
if op.exists("{picard}/FixMateInformation.jar".format(picard=picard)):
jar = "{picard}/FixMateInformation.jar"
else:
jar = "{picard}/picard.jar FixMateInformation"
out = Popen("java -jar -Xmx2G {jar} \
SO=coordinate I=/dev/stdin O=/dev/stdout && sleep 4".format(jar=jar.format(picard=picard)),
stderr=sys.stderr,
stdout=sys.stdout, stdin=PIPE, shell=True)
if sys.version_info[0] > 2:
import io
out.stdin = io.TextIOWrapper(out.stdin)
dedup_sam(dearm_sam(sam_gz, mips), get_umi if umi_length > 0 else None,
out.stdin, mips)
out.stdin.flush()
out.stdin.close()
sys.stdout.flush()
out.wait()
示例5: main
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import stdin [as 别名]
def main (args):
# GNU global
if args["t"] is not None:
try:
output = check_output(["global", "-x", args["t"]]).decode("utf-8")
if output == "":
sys.exit("azcat: symbol ``{0}'' not found".format(args["t"]))
line, file = list(filter(lambda x: x != "", output.split(" ")))[1:3]
line = int(line)
except Exception as e:
sys.exit("azcat: error occurred in global(1)")
# normal
else:
file = args["file"]
line = 1
s = load_file(file)
# get the height of a terminal
try:
height = int(check_output(["stty", "size"], stderr="/dev/stderr").decode("utf-8").split()[0])
except:
height = 50 # failed to get the height so use 50 instead
# if the number of lines is larger than height of the terminal, pipe to a pager
if s.count("\n") > height:
p = Popen(["less", "-R", "+{0}g".format(line)], stdin=PIPE)
try:
pretty_print(file, s, p.stdin, args["with_formatter"], ext=args.get("f"))
p.stdin = sys.stdin
p.wait()
except IOError: # this will raised after the pager existed
pass
else:
out = sys.stdout.buffer
pretty_print(file, s, out, args["with_formatter"], ext=args.get("f"))
示例6: nopen
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import stdin [as 别名]
def nopen(f, mode="r"):
r"""
open a file that's gzipped or return stdin for '-'
if f is a number, the result of nopen(sys.argv[f]) is returned.
>>> nopen('-') == sys.stdin, nopen('-', 'w') == sys.stdout
(True, True)
>>> nopen(sys.argv[0])
<...file...>
# expands user and vars ($HOME)
>>> nopen("~/.bashrc").name == nopen("$HOME/.bashrc").name
True
# an already open file.
>>> nopen(open(sys.argv[0]))
<...file...>
>>> nopen(0)
<...file...>
Or provide nicer access to Popen.stdout
>>> files = list(nopen("|ls"))
>>> assert 'setup.py\n' in files or b'setup.py\n' in files, files
"""
if isinstance(f, int_types):
return nopen(sys.argv[f], mode)
if not isinstance(f, basestring):
return f
if f.startswith("|"):
# using shell explicitly makes things like process substitution work:
# http://stackoverflow.com/questions/7407667/python-subprocess-subshells-and-redirection
# use sys.stderr so we dont have to worry about checking it...
p = Popen(f[1:], stdout=PIPE, stdin=PIPE,
stderr=sys.stderr if mode == "r" else PIPE,
shell=True, bufsize=-1, # use system default for buffering
close_fds=False, executable=os.environ.get('SHELL'))
if sys.version_info[0] > 2:
import io
p.stdout = io.TextIOWrapper(p.stdout)
p.stdin = io.TextIOWrapper(p.stdin)
if mode != "r":
p.stderr = io.TextIOWrapper(p.stderr)
if mode and mode[0] == "r":
return process_iter(p, f[1:])
return p
if f.startswith(("http://", "https://", "ftp://")):
fh = urlopen(f)
if f.endswith(".gz"):
return ungzipper(fh)
if sys.version_info[0] < 3:
return fh
import io
return io.TextIOWrapper(fh)
f = op.expanduser(op.expandvars(f))
if f.endswith((".gz", ".Z", ".z")):
fh = gzip.open(f, mode)
if sys.version_info[0] < 3:
return fh
import io
return io.TextIOWrapper(fh)
elif f.endswith((".bz", ".bz2", ".bzip2")):
fh = bz2.BZ2File(f, mode)
if sys.version_info[0] < 3:
return fh
import io
return io.TextIOWrapper(fh)
return {"r": sys.stdin, "w": sys.stdout}[mode[0]] if f == "-" \
else open(f, mode)