windows - D: Windows 上的 executeShell 运行另一个不立即返回的程序

标签 windows shell d

我使用 D 作为 Windows 7 控制台内容的脚本语言来自动执行无聊的任务。我的一个脚本 (open.exe) 应该允许我从命令行打开东西,而不必指定我使用的程序(我有一个包含这些东西的配置文件)。现在,我使用 executeShell 来执行此操作,并调用类似 start [我要使用的程序名称] [输入文件名称] 之类的东西。如果我直接从 shell 执行此操作,它会立即返回,但如果我使用我的 D 脚本执行此操作,它直到它打开的程序关闭后才会返回。我应该怎么做才能让它立即返回?

出于引用目的,这是我的脚本的业务逻辑(主要方法只是为了管道目的进行一些参数解析):

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);

最佳答案

来自 the std.process documentation 的顶部:

Execute and wait for completion, collect output - executeShell

Windows start 程序生成一个进程并立即退出。 D 的 executeShell 做了其他事情。如果您想生成另一个程序,请使用适当的函数:spawnProcessspawnShell

关于windows - D: Windows 上的 executeShell 运行另一个不立即返回的程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21539288/

相关文章:

linux - 系统重启/关机时未运行初始化脚本

linux - 方法调用顺序混淆

function - D 编译时函数类型提取

windows - 在golang中,程序完成后如何通过双击启动exe来保持控制台窗口打开

c++ - 如何在任务计划程序中显示所有任务

c++ - C 和 C++ 中 struct 的区别

c# - 我该如何修复“"error CS0009: Metadata file "System.Xml.dll'无法打开-图像太小”?

bash - 检查文件是否存在于 "Variable"路径中

php - 将 php 输出作为 shell 脚本运行

macos - Scons 不在 OSX 中构建简单的 D 程序