我正在 Windows 上的 powershell 核心執行 JSL 腳本。有沒有人有一個好方法從 JSL 寫入控制台,以便它寫入我的 powershell 腳本?
目前我正在寫入一個臨時文件,然後在 powershell 腳本中循環檢查該文件並寫入該文件的內容。希望有人做了更強而有力的事。
你可以做這樣的事情。 這是(我的第一個,或多或少)powershell 腳本(感謝 github 和堆棧溢出!)修復桌面文件的路徑...
Write-Output "Starting JMP"
Start-Process -FilePath "jmp.exe" -ArgumentList "C:\Users\v1\Desktop\pstest.jsl"
Write-Output "Started JMP"
# https://gist.github.com/staaldraad/153ab9d26d49c387550bcb5f974f7910
# thanks @ https://gist.github.com/staaldraad
$socket = new-object System.Net.Sockets.TcpListener('0.0.0.0', 1080);
if($socket -eq $null){
exit 1;
}
$socket.start();
$client = $socket.AcceptTcpClient();
$stream = $client.GetStream();
$buffer = new-object System.Byte[] 2048;
# $file = 'c:/afile.exe';
# $fileStream = New-Object System.IO.FileStream($file, [System.IO.FileMode]'Create', [System.IO.FileAccess]'Write');
$encoding = new-object System.Text.AsciiEncoding
do
{
$rawresponse = $null;
while($stream.DataAvailable -or $rawresponse -eq $null) {
$rawresponse = $stream.Read($buffer, 0, 2048);
if ($rawresponse -gt 0) {
$response = $encoding.GetString($buffer, 0, $rawresponse)
# $fileStream.Write($buffer, 0, $read);
$response # really? that's all it takes to print to the console?
}
}
} While ($rawresponse -gt 0);
# $fileStream.Close();
$socket.Stop();
$client.close();
$stream.Dispose();
Write-Output "all done, exit in 5 seconds..."
Start-Sleep -Seconds 5
這是用於桌面的 JSL 腳本 pstest.jsl...
s=socket();
s<<CONNECT></CONNECT>
我認為這是必需的,但在幾次錯誤的開始後無法確定......
Dialog from windows to allow PowerShell to open a port.Dialog from windows to allow PowerShell to open a port.Dialog from windows to allow PowerShell to open a port.來自 Windows 的對話框允許 PowerShell 打開一個端口。
最終
Right-click the .PS1 script on the desktop and ->Run in PowerShell.Right-click the .PS1 script on the desktop and ->Run in PowerShell.Right-click the .PS1 script on the desktop and ->Run in PowerShell.右鍵單擊桌面上的 .PS1 腳本並 -> 在 PowerShell 中運行。
聽起來你需要製作一個 DLL。 JMP 與那些只有一個參數的工具配合得很好。 該參數可能是您的字符串。