D:executeShell在Windows上运行另一个不会立即返回的程序
我正在使用D作为Windows7控制台的脚本语言来自动执行无聊的任务。我的一个脚本(open.exe)应该允许我从命令行打开东西,而不必指定我使用的程序(我有一个配置文件包含这些东西)。现在,我使用D:executeShell在Windows上运行另一个不会立即返回的程序,windows,shell,d,Windows,Shell,D,我正在使用D作为Windows7控制台的脚本语言来自动执行无聊的任务。我的一个脚本(open.exe)应该允许我从命令行打开东西,而不必指定我使用的程序(我有一个配置文件包含这些东西)。现在,我使用executeShell来执行此操作,并调用类似start[name of program of my want use][name of input file][name of input file]的命令。如果我直接从shell执行此操作,它会立即返回,但是如果我使用我的D脚本执行此操作,它在打开
executeShell
来执行此操作,并调用类似start[name of program of my want use][name of input file][name of input file]
的命令。如果我直接从shell执行此操作,它会立即返回,但是如果我使用我的D脚本执行此操作,它在打开的程序关闭之前不会返回。我应该怎么做才能让它立即返回
出于参考目的,这是我的脚本的业务逻辑(main方法只是出于管道目的进行一些参数解析):
}从顶部开始:
执行并等待完成,收集输出-executeShell
Windowsstart
程序生成一个进程并立即退出。D'sexecuteShell
做其他事情。如果要生成另一个程序,请使用以下相应的函数:spawnProcess
或spawnShell
:
执行并等待完成,收集输出-executeShell
Windowsstart
程序生成一个进程并立即退出。D'sexecuteShell
做其他事情。如果要生成另一个程序,请使用相应的函数:spawnProcess
或spawnShell
immutable path = "some//path//going//to//config//file.conf";
void process(string input) {
string extension = split(input,".")[1]; //get file extension from input
auto config = File(path,"r"); auto found = false;
while (!config.eof()){
auto line = chomp(config.readln());
if (line[0]!='#') { //skip comment lines
auto divided = split(line, ":");
if (divided[0] == extension) {
found = true;
auto command = "start " ~ divided[1] ~ " " ~ input;
auto result = executeShell(command);
//test for error code and output if necessary
writeln(result.output);
}
}
}
if (!found)
writeln("ERROR: Don't know how to open " ~ input);