cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
hcarr01
Level VI

RunProgram context closed - SMTP

Bonjour à tous,

 

À partir d’un serveur SMTP, j’essaye d’envoyer des pièces jointes à différentes personnes.
Le script fonctionne correctement.

Le seul problème est que lorsque je rajoute « !// » au début de mon script pour qu’il s’exécute directement, j’obtiens l’erreur suivante :

 

hcarr01_0-1704272297533.png

 

Voici le script que j’utilise :

 

//!

Names Default To Here( 1 );

// modifier le type de codage dans le PowerShell (windows)
stringCommand = "$OutputEncoding = [System.Text.Encoding]::UTF8";


// paramètres du mail à envoyer
commands = {
	"Send-MailMessage -From '... -To '...' -Subject 'test' -Body 'test' -SmtpServer... -Attachment 'test...'", 
	"exit\!n"
};


// script exécution PowerShell
icommand = 0;

RP = Run Program(
	Executable( "PowerShell.exe", stringCommand, ShowWindow("Hide") ),
	ReadFunction( Function( {this}, Write( this << Read ) ) ),
	WriteFunction(
		Function( {this},
			icommand++;
			If( icommand <= N Items( commands ),
				this << Write( commands[icommand] );
			,
				this << WriteEOF;
			);
		)
	)
);

Merci de votre aide !

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Craige_Hales
Super User

Re: SMTP

see https://community.jmp.com/t5/Discussions/Bug-or-Feature/m-p/673679#M86115 .

When it works, you have a script window open the entire time. When it fails, no window is open, and JMP is using a temporary eval context which goes away at the end of the script.

You could probably also work around the issue with a loop at the end of the script that waits for the runprogram to finish before allowing the script to finish. That won't work if you expect to run other JSL or platforms while runprogram works in the background, but approximately like this:

RP=runprogram(...);
while(1,
 // check the message names, there might be another one you need too
 if(RP<<canread == 0 & RP<<canwrite == 0 , break() );
 wait(0.1);
)

That way the eval context will persist until runprogram is done.

Craige

View solution in original post

1 REPLY 1
Craige_Hales
Super User

Re: SMTP

see https://community.jmp.com/t5/Discussions/Bug-or-Feature/m-p/673679#M86115 .

When it works, you have a script window open the entire time. When it fails, no window is open, and JMP is using a temporary eval context which goes away at the end of the script.

You could probably also work around the issue with a loop at the end of the script that waits for the runprogram to finish before allowing the script to finish. That won't work if you expect to run other JSL or platforms while runprogram works in the background, but approximately like this:

RP=runprogram(...);
while(1,
 // check the message names, there might be another one you need too
 if(RP<<canread == 0 & RP<<canwrite == 0 , break() );
 wait(0.1);
)

That way the eval context will persist until runprogram is done.

Craige