cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
The Discovery Summit 2025 Call for Content is open! Submit an abstract today to present at our premier analytics conference.
Choose Language Hide Translation Bar
View Original Published Thread

JSL write to stdout

vince_faller
Super User (Alumni)

I'm running a JSL script from powershell core on windows.  Does anyone have a good way to write to console from JSL so that it writes out to my powershell script? 

Currently I'm writing to a temp file and then in the powershell script checking that file in a loop and writing the contents of that file.  Hoping someone has done something more robust.  

Vince Faller - Predictum
1 ACCEPTED SOLUTION

Accepted Solutions
Craige_Hales
Super User


Re: JSL write to stdout

You could do something like this. Here's (my first ever, more-or-less) powershell script (thanks github and stack overflow!) Fix up the path to the desktop file...


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

Here's a JSL script, pstest.jsl, for the Desktop...

s=socket();
s<<connect("localhost","1080");
s<<send(chartoblob("hello world!"));
s<<close();
quit();

I think this was required, but can't be sure after a couple of false starts...

Dialog from windows to allow PowerShell to open a port.Dialog from windows to allow PowerShell to open a port.

And eventually

Right-click the .PS1 script on the desktop and ->Run in PowerShell.Right-click the .PS1 script on the desktop and ->Run in PowerShell.

Craige

View solution in original post

3 REPLIES 3


Re: JSL write to stdout

It sounds like you need to make a DLL. JMP works well with those that have a single parameter. That argument could be your string.

vince_faller
Super User (Alumni)


Re: JSL write to stdout

Cool.  I'll look into it.  

Vince Faller - Predictum
Craige_Hales
Super User


Re: JSL write to stdout

You could do something like this. Here's (my first ever, more-or-less) powershell script (thanks github and stack overflow!) Fix up the path to the desktop file...


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

Here's a JSL script, pstest.jsl, for the Desktop...

s=socket();
s<<connect("localhost","1080");
s<<send(chartoblob("hello world!"));
s<<close();
quit();

I think this was required, but can't be sure after a couple of false starts...

Dialog from windows to allow PowerShell to open a port.Dialog from windows to allow PowerShell to open a port.

And eventually

Right-click the .PS1 script on the desktop and ->Run in PowerShell.Right-click the .PS1 script on the desktop and ->Run in PowerShell.

Craige