'How launch stats program JMP when a file is saved in a folder?

I want to use a code in PowerShell to launch JMP analysis. To begin I just want to launch the same code any time a file is saved in the folder and after I will adapt this. So I use something I see on this forum to create this code:

### SET FOLDER TO WATCH
    $watcher = New-Object System.IO.FileSystemWatcher
    $watcher.Path = "C:\Users\GROUSD01\Desktop\test"
    $watcher.Filter = "*.xlsx"
    $watcher.EnableRaisingEvents = $true  

### DEFINE ACTIONS AFTER AN EVENT IS DETECTED
    $action = { Start-Process jmp.exe "C:\Users\GROUSD01\Desktop\Création code MPPT\ScriptMPPT.jsl"
              }    
### DECIDE WHICH EVENTS SHOULD BE WATCHED 
    Register-ObjectEvent $watcher "Created" -Action $action 

When I run it in Powershell, it detects the new file and tries to run the command but doesn't find the file .jsl and JMP prints an error. But when I run this code in the command line:

jmp.exe "C:\Users\GROUSD01\Desktop\Création code MPPT\ScriptMPPT.jsl"`

It finds the good file and runs the good things.

Do you have any idea about why is there a problem?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source