Powershell脚本卡住了,从批处理文件调用时不会退出(Powershell script gets stuck, doesn't exit when called from batch

编程入门 行业动态 更新时间:2024-10-11 11:14:03
Powershell脚本卡住了,从批处理文件调用时不会退出(Powershell script gets stuck, doesn't exit when called from batch file)

我有一个连接到网站的PowerShell脚本,并解析其返回的数据(这是关于将以前上传的SQL文件导入网站的数据库)。 PowerShell脚本使用wget ,稍后我可能会用本机函数替换。

导入过程嵌入在由第三方程序scriptFTP执行的脚本中。

当我从单个.bat文件调用它时,脚本运行良好,如下所示:

powershell "& "C:\data\etc\run_import_script.ps1" exit %ERRORLEVEL%

但是,当我从更大的ScriptFTP上下文中调用该.bat文件时,会发生以下情况:

PowerShell脚本被执行 。 我证实了这一点,每次远程导入脚本被调用时,我都会给自己发送一封电子邮件。 PowerShell似乎不会退出,并且脚本执行受阻 。 我仍然可以使用Ctrl + C取消整个事件,但以下命令从未得到执行。

当我将批处理文件更改为以下内容时:

start powershell "& "C:\data\etc\run_import_script.ps1" exit %ERRORLEVEL%

工作 ,在新的控制台中运行PowerShell脚本,但我无法获取PowerShell返回的错误级别。

我试图直接从ScriptFTP调用PowerShell,绕过批处理文件,但结果相同:它只是卡住了。

不显示任何使用Write-Output或Write-Host的PowerShell脚本Write-Output 。

所有程序都在同一个用户下运行,我。

有没有人有什么想法做什么?

I have a PowerShell script that connects to a web site, and parses its returned data (It's about importing a previously uploaded SQL file into the web site's data base). The PowerShell script uses wget, something I may replace by a native function later.

The import process is embedded in a script that is executed by a 3rd party program called scriptFTP.

The script runs fine when I call it from a single .bat file like so:

powershell "& "C:\data\etc\run_import_script.ps1" exit %ERRORLEVEL%

However, when I call this .bat file from within the greater ScriptFTP context, the following happens:

The PowerShell script is executed. I confirmed this my sending myself an E-Mail each time the remote import script got called. PowerShell doesn't seem to exit, and script execution gets stuck. I can still cancel the whole thing using Ctrl+C but the following commands never get executed.

When I change the batch file to the following:

start powershell "& "C:\data\etc\run_import_script.ps1" exit %ERRORLEVEL%

it works, running the PowerShell script in a new console, but I can't grab the error level that PowerShell returns.

I have tried calling PowerShell from ScriptFTP directly, bypassing the batch file, but with the same result: It just gets stuck.

Any output I have the PowerShell script do using Write-Output or Write-Host is not displayed.

All programs run under the same user, me.

Does anybody have any ideas what to do?

最满意答案

尝试添加/ WAIT参数。 它将保持.bat等待,直到PowerShell脚本完成。

START /WAIT powershell "& "C:\data\etc\run_import_script.ps1"

Try adding the /WAIT parameter. It will keep the .bat waiting until the PowerShell script completes.

START /WAIT powershell "& "C:\data\etc\run_import_script.ps1"

更多推荐

本文发布于:2023-08-05 18:34:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1437206.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚本   批处理文件   卡住了   script   Powershell

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!