Estoy ejecutando un script JSL desde PowerShell Core en Windows. ¿Alguien tiene una buena manera de escribir en la consola desde JSL para que escriba en mi script de PowerShell?
Actualmente estoy escribiendo en un archivo temporal y luego en el script de PowerShell comprobando ese archivo en un bucle y escribiendo el contenido de ese archivo. Esperando que alguien haya hecho algo más sólido.
Parece que necesitas hacer una DLL. JMP funciona bien con aquellos que tienen un solo parámetro. Ese argumento podría ser su cadena.
Podrías hacer algo como esto. Aquí está (mi primera, más o menos) secuencia de comandos de powershell (¡gracias github y desbordamiento de pila!) Corrija la ruta al archivo de escritorio...
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
Aquí hay un script JSL, pstest.jsl, para el escritorio...
s=socket();
s<<CONNECT></CONNECT>
Creo que esto era necesario, pero no puedo estar seguro después de un par de comienzos en falso...
Dialog from windows to allow PowerShell to open a port.Dialog from windows to allow PowerShell to open a port.Diálogo desde Windows para permitir que PowerShell abra un puerto.
y eventualmente
Right-click the .PS1 script on the desktop and ->Run in PowerShell.Right-click the .PS1 script on the desktop and ->Run in PowerShell.Haga clic derecho en el script .PS1 en el escritorio y -> Ejecutar en PowerShell.