【发布时间】:2018-10-18 22:18:38
【问题描述】:
我有 2 台 PC,其中 1 台正在监听连接,而另一台正在尝试发送文件。
$dir 是一个文件
"$dir.zip" 是压缩后的 $dir 文件。
我成功运行了这个命令。
Get-Content "$dir.zip" | .\Netcat32.exe serveo.net PORT
但是,我想在后台运行它,这样我就可以运行其他命令了。
我按照 microsoft guides for running jobs 找到了 AsJob 和 Start-Job
这个命令成功了,但是它没有在后台运行:
Invoke-Command -ScriptBlock {Get-Content "$dir.zip" | .\Netcat32.exe serveo.net PORT}
但是,当我在行尾添加 -AsJob 标记时...:
Invoke-Command -ScriptBlock {Get-Content "$dir.zip" | .\Netcat32.exe serveo.net PORT} -AsJob
我收到此错误:
Invoke-Command : Parameter set cannot be resolved using the specified named parameters.
At line:1 char:1
+ Invoke-Command -ScriptBlock {Get-Content "$dir.zip" | .\Netcat32.exe se ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Invoke-Command], ParameterBindingException
+ FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.PowerShell.Commands.InvokeCommandCommand
但是当我将命令更改为以下命令时,我没有收到任何错误,它在后台运行但仍然没有连接:(我注意到 ComputerName 默认为 localhost)
Invoke-Command -ComputerName localhost -ScriptBlock {Get-Content "$dir.zip" | .\Netcat32.exe serveo.net 55558} -AsJob
此命令没有返回错误,在后台运行,但没有连接:
Start-Job -ScriptBlock {Get-Content "$dir.zip" | .\WinGid.exe serveo.net PORT}
也试过了,在 bg 中运行但没有建立 TCP 连接:
Start-Job -ScriptBlock { invoke-Command -ScriptBlock { Get-Content "$dir.zip" | .\WinGid.exe serveo.net PORT } }
【问题讨论】:
-
参见:关于远程处理。
-
您的工作可能在后台失败。执行“start-job ..”后,运行 get-job 以查看该作业的 ID 和状态。如果您看到 status = failed,请执行 receive-job jobid 以查看错误消息。
-
@MikeTwc 它说“已完成”,但我认为它应该无限期运行,除非我向 netcat 提供 -w(秒)。
标签: powershell netcat