cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
hardner
Level V

JSL in .bat file in windows scheduler

I see a previous thread about this that is similar...

My batch file looks the same,

like this:

"C:\Program Files\SAS\JMP\9\jmp.exe" "C:\SCHEDULED\MYSCRIPT.jsl"

but I already have exit(nosave); at the end of my script (and have closed all tables and windows).  And, if I run the .bat file just by clicking on it, it opens JMP, runs the script and then exits as it should.  It's only when I run this .bat file through the Task Scheduler that something isn't right.  It appears to not do the exit().  The script does run and do its thing but a jmp.exe is left open - I can see it in the Task Manager though it's otherwise invisible,  and the task doesn't move on (the scheduler doesn't say it's complete, it waits until the set max time and terminates the task). so the effect is that my automated scripts are getting their work done but over time more and more JMPs are open until I get a memory error (and if I look in the scheduler history my jobs never finish successfully they all get terminated after an hour or whatever).  I tried using tskill in the bat file to close JMP but that didn't help, presumably because it never gets to that step.

I also found I could make the scheduler happy by modifying the batch file to:

start "" "C:\Program Files\SAS\JMP\9\jmp.exe" "C:\SCHEDULED\MYSCRIPT.jsl".  Then it doesn't wait fruitlessly for the thing to end, the scheduler  thinks it's done after starting up the .bat file, but I still have JMP processes left open.  I still can't figure out how to close JMP successfully when I open it in the scheduler.  Maybe I can daily run a task that just does task kill on all open JMPs at some odd hour when I don't expect anything useful to be running.  But I'm hoping for a cleaner solution.

any thoughts about this?

This is JMP9 and Windows7.  And it happens with a variety of different JSL scripts, all of which appear to complete their tasks up to the point of exiting JMP (and do exit JMP outside the scheduler).

1 ACCEPTED SOLUTION

Accepted Solutions

Re: JSL in .bat file in windows scheduler

According to JMP Problem Note 48240, JMP 9.0.3 - 10.0 would crash when the script used with Windows Scheduler included either Quit() or End().  This issue was corrected in JMP 10.0.1.

Wendy

View solution in original post

6 REPLIES 6
euge
Level III

Re: JSL in .bat file in windows scheduler

I've had similar issues with using the exit(nosave) command when using the task scheduler as well...when I run the jsl script in JMP, it works fine.

I haven't seen it actually not close before, but I've gotten the following 2 results (same script, different machines):

1)  the program closes like it's supposed to

2)  I get a "JMP Exception!" alert window which says JMP has performed an access violation and will shut down.  error information will be copied to JMPExcept.jer in the My dcouments folder or the user local application data folder if this is not possible.  The error information can be e-mailed to JMP technical support if necessary.

In my case, I get these results when running the bat file as well, but when I run the JSL script normally from JMP, it works every time.

I've also actually seen where it works sometimes and not others on the same machine.

If anyone has any other experiences (or work arounds), I'd like to hear about them.  I did actually send a email to JMP support and offhand they didn't know why the behavior was different.


hardner
Level V

Re: JSL in .bat file in windows scheduler

I haven't found a root cause solution to the issue.   But you aren't the only person to tell me that exit() doesn't always work.  I do have a work-around now however.

I had to enlist my husband, a real programmer, on this.  Now I owe him a banana cream pie.

This little Powershell program actually solves another JMP-specific problem that may be of interest to somebody.  One of my scripts wants to open up an html address and get tabular information from there.  BUT, the location is password protected.  I could not find a way for JMP to pass my credentials to a web site in JSL, it just fails.  However, it just works without the credentials if I have recently opened the site and entered the credentials in internet explorer.  JMP seems to use the IE cookies.   Anyway, that is the whole reason this program has a command line option called "loginpage".  It's superfluous to the JMP exiting issue but it optionally opens IE at a certain web page, passes the hardcoded credentials if needed and then closes IE.

"waitforlog" IS relevant.  The way this scheme works is that when the JMP script runs it posts a certain log file at the end when it's done.  unlike exit() this seems to occur reliably.   This program deletes any previous version of that file, opens JMP, run the script then waits for the file to reappear.  When it does it knows it can kill JMP and it has worked out the process id of the instance of JMP that it opened and kills just that instance.

I had an earlier workaround using taskkill to periodically kill all open JMPs but it seems that it's not easy in a simple batch file to know what particular instance you just started so you can kill that specific instance with taskkill.  Since I have many scheduled jobs and also want to use this machine to open JMP and do some manual work while the jobs run in the background it wasn't a very good solution to just be killing off JMP instances willy nilly.  Powershell seems to have a special power to identify a specific instance of a program you just started.

Anyway this Powershell solution is working for me now, for both issues....

Here's an example of the syntax in a .bat file running it....(with the last two things optional)

powershell "&"C:\SCHEDULED\runJMPscript.ps1" -script 'C:\SCHEDULED\yourJSLscript.JSL' -waitforlog -loginpage

Like I said, I didn't write this myself and the login part is based on something I found in another forum about starting IE and getting it to do more things that were possible just in a simple batch file.   Still, it's fairly comprehensible.   Note that the location of JMP is hardcoded in there and you'd need to alter your script to make it create the log file with the name that's the script name  with .log extension.

#*****************************************************************************

#

# RunJmpScript.ps1 - PowerShell script used to run a Jmp command

#

# Usage:

#

#  powershell.exe RunJmpScript.ps1 [-loginpage] -script scriptname [-waitforlog]

#

#*****************************************************************************

param ([switch]$loginpage, [string]$script = "unknown", [switch]$waitforlog)

#

# Check the command-line options for errors

#

Write-Host "loginpage: $loginpage"

Write-Host "script: $script"

Write-Host "waitforlog: $waitforlog"

$scriptexists = (Test-Path $script -PathType Leaf)

if (!($scriptexists))

{

  Write-Host "Error: Must specify the location of a Jmp script file using -script <path>"

  exit 1

}

#

# Retrieve the login page info if needed

#

if ($loginpage)

{

  # Define some variables that will change based on your configuration

  # I recommend storing these an XML file and reading them in at execution

  # time, but for the sake of this exercise i'm keeping it simple.

  $username = "fill in username here"

  $password = "fill in pwd here"

  $url = "fill in URL here"

  # Create the IE com object

  $ie = new-object -com InternetExplorer.Application

  # Navigate to the login page

  $ie.navigate($url)

  # Wait for the page to finish loading

  do {sleep 1} until (-not ($ie.Busy))

  #$ie.visible = $true #Uncomment this for debugging

  # Assign the DOM to the $doc variable

  $doc = $ie.document

  # Fill in login info

  try {

    # Find the username field and set the value to that of our variable

    $usernameField = $doc.getElementById('USER')

    $usernameField.value = $username

    # Find the password field and set the value to that of the result

    # of a call to the get-password function with the paramter defined at top

    $passwordField = $doc.getElementById('PASSWORD')

    $passwordField.value = $password

    # Find and click the submit button

    $submitButton = $doc.getElementById('Submit')

    $submitButton.click()

    # Wait until login is complete

    do {sleep 1} until (-not ($ie.Busy))

  } catch {$null}

  # Wait for the page to finish loading

  do {sleep 1} until (-not ($ie.Busy))

  # Close IE

  $ie.quit()

}

#

# Remove the current log file if we are going to monitor it

#

$logfile = $script + ".log"

if ($waitforlog)

{

  if (Test-Path $logfile -PathType Leaf)

  {

    Write-Host "Removing existing log file $logfile"

    Remove-Item $logfile

  }

}

#

# Execute the Jmp command, using the specified script

#

$exe = "C:\Program Files\SAS\JMP\9\jmp.exe"

$exeargs = "`"" + $script + "`""

Write-Host "Starting process $exe with argument: $exeargs"

$jmp = start-process $exe "$exeargs" -passthru

#

# See if we need to wait for this to write out a log file.

#

if ($waitforlog)

{

  $logfile = $script + ".log"

  $idval = $jmp.Id

  Write-Host "Waiting for log file $logfile from process $idval"

  while (!(Test-Path $Logfile -PathType Leaf))

  {

    # If the process exits, we can just quit now

    if ($jmp.HasExited)

    {

      exit 0

    }

    # Otherwise, wait for a bit, and try again

    Start-Sleep -s 1

  }

  Write-Host "Stopping external program $idval"

  Stop-Process $idval

}

exit 0

euge
Level III

Re: JSL in .bat file in windows scheduler

Thanks for the suggestion!

Unfortunately I'm still getting the JMP execution error even after running the powershell script...so strange.

For anybody else following this thread, I had to enable powerscript shell script execution using the set-executionpolicy remotesigned -scope currentuser command at the powerscript prompt to allow the script to run...

msharp
Super User (Alumni)

Re: JSL in .bat file in windows scheduler

Replying to better follow this thread.  The powershell solution won't completely fix my issue since my script appears to hang just before the Exit(); command.  My script hangs at a NW << Save Journal("path") just before Exit();.  Although, for everything else I have the exact same issue, running the script manually or through the .bat file yields no issue.  Only when I run the script through the task scheduler does it ever hang.

tsl
tsl
Level III

Re: JSL in .bat file in windows scheduler

I've observed the same problem as has been described. But I found a very simple solution.

I noticed that when I run JMP interactively, that when I close it down if there are any files open ( e.g. scripts ), I always get a "Save Session" dialog which asks me "Do you want JMP to remember the open files and reports and re-open them next time?"

There are Yes, No and Cancel buttons and a check box to "Do not ask me again about saving the session".

I suspected that this dialog is appearing in batch mode too and that JMP is sitting there waiting for a response.

So I checked the "Do not ask me again" box and closed JMP down.

Then manually triggered my batch job in Task Scheduler....and what do you know, it ran successfully and terminated properly with "the operation completed successfully" noted in the task scheduler.

Re: JSL in .bat file in windows scheduler

According to JMP Problem Note 48240, JMP 9.0.3 - 10.0 would crash when the script used with Windows Scheduler included either Quit() or End().  This issue was corrected in JMP 10.0.1.

Wendy