通过 netcat 传输文件作为 Powershell 中的后台作业
Transfer file via netcat as a background job in Powershell
我有 2 台电脑,其中一台正在侦听连接,另一台正在尝试发送文件。
$dir 是一个文件
"$dir.zip" 是压缩的 $dir 文件。
我运行这个命令成功了。
Get-Content "$dir.zip" | .\Netcat32.exe serveo.net PORT
不过,我想运行它在后台,这样我就可以运行其他命令。
我遵循了 运行ning 作业的 Microsoft 指南,找到了 AsJob 和 Start-Job
此命令成功,但在后台未成功运行:
Invoke-Command -ScriptBlock {Get-Content "$dir.zip" | .\Netcat32.exe serveo.net PORT}
但是,当我在行尾添加 -AsJob 标签时...:[=17=]
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
但是当我将命令更改为以下命令时,我没有收到任何错误,它 运行s 在后台 运行d 但仍然没有连接:(我注意到 ComputerName 是本地主机默认)
Invoke-Command -ComputerName localhost -ScriptBlock {Get-Content "$dir.zip" | .\Netcat32.exe serveo.net 55558} -AsJob
这条命令returns没有错误,运行s在后台,但是没有实现连接:
Start-Job -ScriptBlock {Get-Content "$dir.zip" | .\WinGid.exe serveo.net PORT}
也试过了,运行s in bg 但没有建立 TCP 连接:
Start-Job -ScriptBlock { invoke-Command -ScriptBlock { Get-Content "$dir.zip" | .\WinGid.exe serveo.net PORT } }
您可以尝试启动进程
start powershell -Argumentlist "Get-Content $dir.zip | .\Netcat32.exe serveo.net PORT" -noNewWindow
如果您知道如何在 cmd 中执行此操作,下面的选项可能会起作用
start ./netcat32.exe -ArgumentList "..." -nonewwindow
或start-job {cmd /c "netcat32 ..."}
我有 2 台电脑,其中一台正在侦听连接,另一台正在尝试发送文件。
$dir 是一个文件
"$dir.zip" 是压缩的 $dir 文件。
我运行这个命令成功了。
Get-Content "$dir.zip" | .\Netcat32.exe serveo.net PORT
不过,我想运行它在后台,这样我就可以运行其他命令。
我遵循了 运行ning 作业的 Microsoft 指南,找到了 AsJob 和 Start-Job
此命令成功,但在后台未成功运行:
Invoke-Command -ScriptBlock {Get-Content "$dir.zip" | .\Netcat32.exe serveo.net PORT}
但是,当我在行尾添加 -AsJob 标签时...:[=17=]
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
但是当我将命令更改为以下命令时,我没有收到任何错误,它 运行s 在后台 运行d 但仍然没有连接:(我注意到 ComputerName 是本地主机默认)
Invoke-Command -ComputerName localhost -ScriptBlock {Get-Content "$dir.zip" | .\Netcat32.exe serveo.net 55558} -AsJob
这条命令returns没有错误,运行s在后台,但是没有实现连接:
Start-Job -ScriptBlock {Get-Content "$dir.zip" | .\WinGid.exe serveo.net PORT}
也试过了,运行s in bg 但没有建立 TCP 连接:
Start-Job -ScriptBlock { invoke-Command -ScriptBlock { Get-Content "$dir.zip" | .\WinGid.exe serveo.net PORT } }
您可以尝试启动进程
start powershell -Argumentlist "Get-Content $dir.zip | .\Netcat32.exe serveo.net PORT" -noNewWindow
如果您知道如何在 cmd 中执行此操作,下面的选项可能会起作用
start ./netcat32.exe -ArgumentList "..." -nonewwindow
或start-job {cmd /c "netcat32 ..."}