以上就是给各位分享Subprocess.call或Subprocess.Popen无法使用PATH,其中也会对Linux/Windows中的可执行文件进行解释,同时本文还将给你拓展.bat文件中的@p
以上就是给各位分享Subprocess.call或Subprocess.Popen无法使用PATH,其中也会对Linux / Windows中的可执行文件进行解释,同时本文还将给你拓展.bat 文件中的 @pause 阻止 subprocess.Popen 完成、C ++ forksubprocess,请求subprocess列表,在Linux中杀死进程、C ++ Windows CreateChildProcess – 隐藏/不显示subprocess的控制台窗口、Flowable runtimeService.startProcessInstanceByKey('MY_SUBPROCESS_KEY') 执行但 superProcessId null等相关知识,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:- Subprocess.call或Subprocess.Popen无法使用PATH(Linux / Windows)中的可执行文件(无法调用proc)
- .bat 文件中的 @pause 阻止 subprocess.Popen 完成
- C ++ forksubprocess,请求subprocess列表,在Linux中杀死进程
- C ++ Windows CreateChildProcess – 隐藏/不显示subprocess的控制台窗口
- Flowable runtimeService.startProcessInstanceByKey('MY_SUBPROCESS_KEY') 执行但 superProcessId null
Subprocess.call或Subprocess.Popen无法使用PATH(Linux / Windows)中的可执行文件(无法调用proc)
我正在编写一个程序,该程序需要同时在Linux和Windows上运行,并使用
路径中存在的可执行文件(带有参数)。(假定)
目前,我在使用
Subprocess.Call和Subprocess.Popen在Windows中运行可执行文件时遇到麻烦。
对于这样的代码,在Windows 8中
def makeBlastDB(inFile,inputType,dbType,title,outDir):
strProg = 'makeblastdb'
strInput = '-in ' + inFile
strInputType = '-input_type ' + inputType
strDBType = '-dbtype ' + dbType
strTitle = '-title ' + title
strOut = '-out ' + os.path.join(os.sep,outDir,title)
cmd = [strProg,strInput,strInputType,strDBType,strTitle,strOut]
result = Popen(cmd,shell=True)
我在控制台中收到错误消息
'makeblastdb' is not recognized as an internal or external command,operable program or batch file.
即使我可以使用cmd.exe运行相同的命令,但
在shell = False时仍会得到相同的响应。
假设可执行文件位于PATH
环境变量中,关于如何运行命令的任何想法?谢谢
.bat 文件中的 @pause 阻止 subprocess.Popen 完成
如何解决.bat 文件中的 @pause 阻止 subprocess.Popen 完成?
我正在尝试使用以下代码(Win10 btw)将一个简单的 .bat 脚本的输出通过管道传输到我的 python 脚本:
import subprocess
p = subprocess.Popen(C:\Users\Public\gamess-64\get-version-names.bat),stdout=subprocess.PIPE)
output = p.communicate()
print(output)
问题是脚本看起来像这样:
::
:: Mar 08,2015 :: Sarom Leang :: get-version-names.bat
::
:: Looks in current directory for gamess.*.exe and outputs the
:: version names to be used in ''rungms.bat'' or ''rungms-serial.bat''
::
@setlocal enabledelayedexpansion
@echo ------ -------
@echo Binary Version
@echo ====== =======
@echo.
@for %%f in (gamess.*.exe) do @(
@set temp=%%~nf
@set version=!temp:gamess.=!
@echo %%f !version!)
@echo.
@pause
@pause
阻止我的 py 脚本通过 subprocess.popen()
所以我想知道如何在我的脚本不被停止的情况下获得 stdout
(并且不只是删除 @暂停)。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
C ++ forksubprocess,请求subprocess列表,在Linux中杀死进程
我试图创build一个subprocess,发送subprocess命令“LISTALL”。 subprocess然后应该向系统发出命令ps并将该列表返回给父进程。 父进程应该select一个进程并杀死它。 这是我迄今为止,但我只是得到它运行麻烦。
#include <stdio.h> #include <unistd.h> #include <cstring> #include <stdlib.h> #include <iostream> #include <sys/wait.h> char* getlistofProcesses(const char* cmd) { FILE* pipe = popen(cmd,"r"); if (!pipe) return (char*)"ERROR"; char buffer[128]; char *result = new char[1024]; while(!feof(pipe)) { if(fgets(buffer,128,pipe) != NULL) strcat(result,buffer); } pclose(pipe); return result; } int spawnGEdit() { pid_t gPid = fork(); if(gPid == 0) { execl("gedit","gedit",NULL); exit(-1); } else { } return 0; } int main(int argc,char **argv) { int P2C[2]; int C2P[2]; pipe(P2C); pipe(C2P); pid_t cPid = fork(); char cmd[50]; char* listofProcesses = new char[1024]; spawnGEdit(); if (cPid == 0) { close(P2C[1]); close(C2P[0]); read(P2C[0],cmd,10); if(strcmp(cmd,"LISTALL") == 0) { write(C2P[1],getlistofProcesses("ps"),1024); close(P2C[0]); close(C2P[1]); } } else if (cPid > 0) { close(C2P[1]); close(P2C[0]); write(P2C[1],"LISTALL",10); wait(NULL); read(C2P[0],listofProcesses,1024); printf("%s",listofProcesses); //Todo //get user input of a PID //kill the PID close(C2P[0]); close(P2C[1]); } else { // fork Failed printf("Forking Failed!n"); exit(1); } return 0; }
这些是我在尝试编译时遇到的错误:
/tmp/cciTPIOZ.o: In function `getlistofProcesses(char const*)': test.cpp:(.text+0x53): undefined reference to `operator new[](unsigned long)' /tmp/cciTPIOZ.o: In function `main': test.cpp:(.text+0x166): undefined reference to `operator new[](unsigned long)' /tmp/cciTPIOZ.o: In function `__static_initialization_and_destruction_0(int,int)': test.cpp:(.text+0x2c0): undefined reference to `std::ios_base::Init::Init()' test.cpp:(.text+0x2cf): undefined reference to `std::ios_base::Init::~Init()' collect2: error: ld returned 1 exit status
我正在编译:
cc test.cpp -o test
有pipe道,叉子,dup2的问题
clone()系统调用是否最终依赖于fork函数?
具体来说,fork()如何在Linux中处理从malloc()dynamic分配的内存?
C多个进程写入1个pipe道
使用pipe道发送多个string到subprocess
从pipe道读取()保证在EOF之前提供所有primefaces写入的数据?
subprocess在使用共享内存时挂起?
如何复制当前进程?
父母怎样才能用一根pipe子给n个孩子发消息?
PHP:pcntl_fork()真的做什么?
编译错误行号:9,53,64可以通过使用这些解决:
第9行: FILE* pipe = popen(cmd.data(),"r");
第53行: write(C2P[1],getlistofProcesses("ps").data(),1024);
第64行: printf("%s",listofProcesses.data());
原因:这些popen,write,printf需要char *作为它们的参数,但是你传递它们的std :: string。 你必须使用std :: string.data()函数,因为它返回指向由std::string对象表示的字符数组的指针。
对于你在第63行的错误,请参考这个 。
PS: – 对于您所编辑的问题:
第10行: if (!pipe) return (char*)"ERROR";
第12行: char *result = new char[1024];
第53行:(在第7行中更改) char* getlistofProcesses(const char* cmd)
有点建议:使用wait(NULL); 在读取listofProcesses和exit(0);之前的父进程中exit(0); 在子进程结束时。
工作代码:
#include <stdio.h> #include <unistd.h> #include <cstring> #include <stdlib.h> #include <iostream> #include <sys/wait.h> char* getlistofProcesses(const char* cmd) { FILE* pipe = popen(cmd,1024); close(P2C[0]); close(C2P[1]); } exit(0); } else if (cPid > 0) { close(C2P[1]); close(P2C[0]); write(P2C[1],listofProcesses); //Todo //get user input of a PID //kill the PID close(C2P[0]); close(P2C[1]); } else { // fork Failed printf("Forking Failed!n"); exit(1); } return 0; }
C ++ Windows CreateChildProcess – 隐藏/不显示subprocess的控制台窗口
我需要创build一个subprocess作为我的主进程的套接字监听器/服务器,我使用这个调用来实现目标:
bSuccess = CreateProcessA(NULL,cmdLineArgs,// command line NULL,// process security attributes NULL,// primary thread security attributes TRUE,// handles are inherited HIGH_PRIORITY_CLASS,// creation flags NULL,// use parent's environment NULL,// use parent's current directory &siStartInfo,// STARTUPINFO pointer &piProcInfo); // receives PROCESS_informatION
任何人都可以说出需要做什么才能使subprocess窗口不显示? 每当主要的中央过程创build一个孩子时,都不希望有一个可见的过程窗口。
后来编辑我用过:
HWND hWnd = GetConsoleWindow(); if (hWnd != 0) { ShowWindow( hWnd,SW_HIDE); }
在subprocess的主要function,但这不是真的最好的解决scheme,因为窗口仍然显示了几分之一秒。 如果一个人有几个subprocess,每个进程都有自己的窗口冒泡到屏幕上,它仍然不是优雅的。 是否有任何标志为编译器设置产生“无控制台”输出?
有没有办法使窗口输出ansi转义序列
Windows环境variables中的控制台宽度
Go编译器有一个窗口设置选项吗?
我无法得到urwid教程的例子工作
如何更改命令提示符/控制台窗口/ DOS框中的制表符?
我正在使用Visual Studio 2010。
格式化用户input的货币
Windows控制台的颜色值是否有与之相关的正式名称(常量)?
如何移动到C ++的前一行?
Windows 10registry不能被代码删除
在Windows中使用GUI应用程序中的控制台,仅在其从控制台运行时使用
CREATE_NO_WINDOW标志仅用于此目的。
你可以像下面这样把它添加到dwCreationFlags位掩码中:
bSuccess = CreateProcessA(NULL,// handles are inherited HIGH_PRIORITY_CLASS | CREATE_NO_WINDOW,// STARTUPINFO pointer &piProcInfo); // receives PROCESS_informatION
您必须使用您提供的STARTUPINFO结构作为CreateProcess参数。
STARTUPINFO StartInfo= {sizeof(StartInfo)}; StartInfo.dwFlags= STARTF_USESHOWWINDOW; StartInfo.wShowWindow= SW_HIDE;
siStartInfo.dwFlags &= STARTF_USESHOWWINDOW; siStartInfo.wShowWindow = SW_HIDE;
应该这样做
另请参见http://msdn.microsoft.com/en-us/library/windows/desktop/ms686331(v=vs.85).aspx
Flowable runtimeService.startProcessInstanceByKey('MY_SUBPROCESS_KEY') 执行但 superProcessId null
是否需要通过runtimeService来运行进程?尝试使用 callActivity。
UPD:
为了在循环中启动子进程的多个实例,可以使用带有 Multi-instance 标记的 callActivity。
关于Subprocess.call或Subprocess.Popen无法使用PATH和Linux / Windows中的可执行文件的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于.bat 文件中的 @pause 阻止 subprocess.Popen 完成、C ++ forksubprocess,请求subprocess列表,在Linux中杀死进程、C ++ Windows CreateChildProcess – 隐藏/不显示subprocess的控制台窗口、Flowable runtimeService.startProcessInstanceByKey('MY_SUBPROCESS_KEY') 执行但 superProcessId null等相关内容,可以在本站寻找。
本文标签: