Sto eseguendo uno script JSL dal core di PowerShell su Windows.Qualcuno ha un buon modo per scrivere sulla console da JSL in modo che scriva sul mio script PowerShell?
Attualmente sto scrivendo su un file temporaneo e quindi nello script di PowerShell controllando quel file in un ciclo e scrivendo il contenuto di quel file.Sperando che qualcuno abbia fatto qualcosa di più robusto.
Sembra che tu debba creare una DLL. JMP funziona bene con quelli che hanno un singolo parametro. Quell'argomento potrebbe essere la tua stringa.
Potresti fare qualcosa del genere. Ecco (il mio primo script PowerShell in assoluto, più o meno) (grazie a github e stack overflow!) Correggi il percorso del file desktop ...
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
Ecco uno script JSL, pstest.jsl, per il desktop...
s=socket();
s<<CONNECT></CONNECT>
Penso che fosse necessario, ma non posso esserne sicuro dopo un paio di false partenze...
Finestra di dialogo da Windows per consentire a PowerShell di aprire una porta.
Ed eventualmente
Fare clic con il pulsante destro del mouse sullo script .PS1 sul desktop e -> Esegui in PowerShell.