在Powershell中使用start-process和-wait命令

时间:2016-11-01 13:18:21

标签: powershell

我是Powershell的新手,并没有太多的编程背景,只是试图将它用于软件包装。无论如何,我发现了带-Wait参数的start-process命令,它适用于大多数事情。我注意到的是,它不仅等待你指定的进程,它等待任何子进程,即使在主进程不再运行之后。通常这很好,但我有一个奇怪的情况。我正在使用start-process运行复杂的Oracle批处理文件。批处理文件最终运行setup.exe,这是我真正想要等待的,但是其他进程也会产生永不停止。因此,如果我使用-wait参数,即使setup.exe不再运行,脚本也不会停止。我发现的最接近的是:

saps -FilePath "Path\config.bat" -ArgumentList "arguments"
Start-Sleep -s 10
Wait-Process -Name "setup"

这很有效,但我认为在没有使用超时命令的情况下,这是更好的方法。有什么想法吗?

2 个答案:

答案 0 :(得分:12)

您可以轻松使用此命令:

$myprocss = Start-Process "powershell" -PassThru 
$myprocss.WaitForExit()

此过程结束时此命令将继续。

答案 1 :(得分:1)

使用 > react-scripts build Creating an optimized production build... Failed to compile. Class constructor Parser cannot be invoked without 'new' ,有一个等待选项:

import * as mongoose from 'mongoose';
export const LinksCacheSchema = new Schema({
    ts: {
        type: Date,
        default: Date.now()
    },
    imdbId: String,
    parentLink: String,
    playableLink: String,
    status: String,
    title: String,
    size: Number,
    contentType: String,
}, { collection: 'links_cache' });

export const LinksCacheList = mongoose.model('LinksCache', LinksCacheSchema);


const linkInfo = await LinksCacheList.findById(documentId); //this is the one returning type of any instead of LinksCacheSchema or any specific type
相关问题