我正在 Windows 上的 powershell core 中运行 JSL 脚本。有人有从 JSL 写入控制台的好方法吗,以便将其写入我的 powershell 脚本?
目前,我正在写入一个临时文件,然后在 powershell 脚本中循环检查该文件并写入该文件的内容。希望有人能做一些更强大的事情。
听起来您需要制作一个DLL。 JMP 适用于具有单个参数的那些。 该参数可能是您的字符串。
你可以做这样的事情。 这是(我的第一个,或多或少)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.来自 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.右键单击桌面上的 .PS1 脚本,然后 -> 在 PowerShell 中运行。