Tag: 进程

如何从外部进程将数据写入现有进程的STDIN?

我正在寻求从外部进程向现有进程的STDIN写入数据的方法,并发现了类似的问题如何在Python中将数据stream式传输到来自不同本地/远程进程的程序的STDIN中? 在stackoverlow中。 在这个线程中,@Michael说我们可以像下面那样获取现有进程的文件描述符,并允许在Linux上写入数据。 /proc/$PID/fd/ 所以,我创build了一个下面列出的简单脚本来testing从外部进程向脚本的STDIN (和TTY )写入数据。 #!/usr/bin/env python import os, sys def get_ttyname(): for f in sys.stdin, sys.stdout, sys.stderr: if f.isatty(): return os.ttyname(f.fileno()) return None if __name__ == "__main__": print("Try commands below") print("$ echo 'foobar' > {0}".format(get_ttyname())) print("$ echo 'foobar' > /proc/{0}/fd/0".format(os.getpid())) print("read :: [" + sys.stdin.readline() + "]") 这个testing脚本显示STDIN和TTYpath,然后等待一个写它的STDIN 。 我启动了这个脚本,在下面得到消息。 Try commands […]

从Process.StandardOutput中捕获二进制输出

在C#中(在SuSE上运行在Mono 2.8下的.NET 4.0),我想运行一个外部批处理命令并以二进制forms捕获它的输出。 我使用的外部工具称为“samtools”(samtools.sourceforge.net),除此之外,它可以从一个名为BAM的索引二进制文件格式返回logging。 我使用Process.Start来运行外部命令,我知道我可以通过redirectProcess.StandardOutput来捕获它的输出。 问题是,这是一个带有编码的文本stream,所以它不能访问输出的原始字节。 我find的几乎可行的解决scheme是访问基础stream。 这是我的代码: Process cmdProcess = new Process(); ProcessStartInfo cmdStartInfo = new ProcessStartInfo(); cmdStartInfo.FileName = "samtools"; cmdStartInfo.RedirectStandardError = true; cmdStartInfo.RedirectStandardOutput = true; cmdStartInfo.RedirectStandardInput = false; cmdStartInfo.UseShellExecute = false; cmdStartInfo.CreateNoWindow = true; cmdStartInfo.Arguments = "view -u " + BamFileName + " " + chromosome + ":" + start + "-" + […]

如何使用pid从Python中终止进程?

我想在Python中写一些简短的脚本,如果不是已经开始,terminal和应用程序(Linux)将启动另一个子程序中的Python代码。 所以它看起来像: #!/usr/bin/python from subprocess import Popen text_file = open(".proc", "rb") dat = text_file.read() text_file.close() def do(dat): text_file = open(".proc", "w") p = None if dat == "x" : p = Popen('python StripCore.py', shell=True) text_file.write( str( p.pid ) ) else : text_file.write( "x" ) p = # Assign process by pid / pid from int( […]

如何在远程机器上执行进程,在C#

我怎样才能在远程计算机上启动一个进程,说计算机名=“someComputer”,使用System.Diagnostics.Process类? 我在远程计算机上创build了一个小型控制台应用程序,它只是将“Hello world”写入一个txt文件,我想远程调用它。 控制台应用程序path:c:\ MyAppFolder \ MyApp.exe 目前我有这个: ProcessStartInfo startInfo = new ProcessStartInfo(string.Format(@"\\{0}\{1}", someComputer, somePath); startInfo.UserName = "MyUserName"; SecureString sec = new SecureString(); string pwd = "MyPassword"; foreach (char item in pwd) { sec.AppendChar(item); } sec.MakeReadOnly(); startInfo.Password = sec; startInfo.UseShellExecute = false; Process.Start(startInfo); 我不断收到“networkingpath未find”。

正确的方式(在.NET中)将焦点切换到另一个应用程序

这是我迄今为止: Dim bProcess = Process.GetProcessesByName("By").FirstOrDefault If bProcess IsNot Nothing Then SwitchToThisWindow(bProcess.MainWindowHandle, True) Else Process.Start("C:\Program Files\B\B.exe") End If 它有两个问题。 有人告诉我,SwitchToThisWindow是depricated。 如果应用程序B被最小化,则从用户的angular度来看,该function静静地失败。 那么做正确的方法是什么?

用pipe道连接几个Popen命令

我知道如何运行命令使用cmd = subprocess.Popen,然后subprocess.communicate。 大多数情况下,我使用一个用shlex.split标记的string作为Popen的“argv”参数。 “ls -l”的例子: import subprocess import shlex print subprocess.Popen(shlex.split(r'ls -l'), stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE).communicate()[0] 但是,pipe道似乎不工作…例如,下面的示例返回注意: import subprocess import shlex print subprocess.Popen(shlex.split(r'ls -l | sed "s/a/b/g"'), stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE).communicate()[0] 你能告诉我我做错了吗? 谢谢

如何更改Java应用程序进程的名称?

执行Java应用程序时,给它的进程名称通常是java.exe或javaw.exe 。 但是我怎样才能让我的应用程序的名称叫它?

Androidstream程杀手

也许你可以帮忙。 是否有可能获得在Android系统中运行的所有Processes列表,并杀死其中的一些? 我知道有一些应用程序( task managers ),但我想写我自己的,简单的应用程序。 我想编写简单的任务pipe理器,只是列出所有进程和button,将杀死其中的一些。 你能不能写一些我可以调用的Java方法来获得进程列表和杀死它们的方法。 或者只是给我一些build议。

在Linux中的最大进程数

在linux系统中可能的进程数量的最大限制是多less? 我们怎么find它?

Runtime.getRuntime()。exec()不起作用

我需要从一个程序执行一个命令。 命令行是好的,我在terminal上试了一下,但是在程序中不起作用。 我从我的代码中添加一个副本: File dir = new File("videos"); String[] children = dir.list(); if (children == null) { // Either dir does not exist or is not a directory System.out.print("No existe el directorio\n"); } else { for (int i=0; i<children.length; i++) { // Get filename of file or directory String filename = children[i]; //Recojo el momento […]