INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Feature request - ShellRun(), Before playback expression  (Read 778 times)

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2674
Feature request - ShellRun(), Before playback expression
« on: November 27, 2024, 04:12:07 am »

Feature request for this usecase and many others:

1. Add "Before playback expression..." setting. Should execute when transitioning from STOPPED to PLAYING and when changing track, but not from PAUSED state. a SEEK should also not trigger it.

2. New Expression Language function:
ShellRun(command, args, flags, timeout)

  command: shell command to execute (path to executable or .bat file)
  args: optional arguments, e.g.: filekey() [width] [height]
  flags: optional; 1=hidden, 2=KillOnTimeout, 4=CaptureStdout, 8= ... [flags values are added, 3=1+2]
  timeout: optional, default=0; timeout in seconds to wait for command to finish. 0 means "do not wait", just start the process

With timeout>0:
- Mouse cursor can change to "busy" or some other custom icon/spinner while a command is executing, to provide some feedback to the user. Alternatively, show some on-screen indicator/notification somewhere.
- Pressing ESC or clicking the notification could immediately return from execution (forced timeout)
- On timeout, process should be killed only if "KillOnTimeout" flag is set.

Bonus: An "outputField" parameter could also be added - STDOUT would then be saved to this field. Alternatively, the CaptureStdout flag makes ShellRun() return the STDOUT output, allowing for things like setting a field to =ShellRun(c:\tools\getInfo.bat) in the Tag Editor.
Logged

lepa

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2036
Re: Feature request - ShellRun(), Before playback expression
« Reply #1 on: November 28, 2024, 11:29:01 am »

would open interesting possibilities I'm sure
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42441
  • Shoes gone again!
Re: Feature request - ShellRun(), Before playback expression
« Reply #2 on: December 02, 2024, 08:25:46 am »

We'll start with this one:
NEW: Added a before playback expression.

Run commands would be possible, but they take a list of arguments. Would you separate them with a semi-colon?

Thanks.
Logged
Matt Ashland, JRiver Media Center

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2674
Re: Feature request - ShellRun(), Before playback expression
« Reply #3 on: December 02, 2024, 09:09:34 am »

Thank you Matt!

args could be a standard list if that makes it easier, yes.
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42441
  • Shoes gone again!
Re: Feature request - ShellRun(), Before playback expression
« Reply #4 on: December 02, 2024, 10:02:53 am »

Next build we'll try this too:
NEW: Added a ShellRun expression.

Thanks for the help :)
Logged
Matt Ashland, JRiver Media Center

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2674
Re: Feature request - ShellRun(), Before playback expression
« Reply #5 on: December 03, 2024, 10:04:26 am »

Some ShellRun() issues:

1.when called with blank 'args', it seems to default to some arg string used in a previous ExpressionLanguage function
   test with replace(thisText,this,that) ShellRun(notepad) - notepad asks if you want to create 'this.txt'

2. function returns the 'command' arg value (ie, "cmd") instead of the STDOUT
   test with ShellRun(cmd,//c;echo;testOutput) - returns "cmd", expected "testOutput"

3. calling with an invalid/unknown executable name results in a Windows popup (file not found)
   test with ShellRun(someInvalidProg)

4. Flags are not implemented? There's always a flashing window for console programs even with Hidden=1

5. Timeout is not implemented? MC seems to always wait for process exit even with timeout=0 - it should return immediately with no output capture. Timeout>0 also does nothing.

Otherwise it seems to work :)
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42441
  • Shoes gone again!
Re: Feature request - ShellRun(), Before playback expression
« Reply #6 on: December 03, 2024, 10:35:36 am »

It just wasn't checking the number of arguments. That will be fixed next build.

I didn't add a timeout. You can block or not block.

I'll make it return the string from the call if you block.

Thanks for the help.
Logged
Matt Ashland, JRiver Media Center

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2674
Re: Feature request - ShellRun(), Before playback expression
« Reply #7 on: December 05, 2024, 10:14:36 am »

Tested build 47 49 - most issues above are fixed :)

ShellRun now works only with full path to the executable (ie, "c:\windows\system32\cmd.exe"). On build 48 it was working with just "cmd" or "python" which was easier. Can that be reverted?

Otherwise it seems to work! Can you please confirm the flags:
bit 1 = Wait for exit and return STDOUT
bit 2 = Create no window (hidden)

The args parameter is working both as a list and as a single string (on windows), ie, "//c;dir;c:\" works the same as "//c dir c:\". That's fine.
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42441
  • Shoes gone again!
Re: Feature request - ShellRun(), Before playback expression
« Reply #8 on: December 05, 2024, 10:45:06 am »

From the tooltip:
1: blocking, 2: hidden

It was using ShellExecuteEx but switched to CreateProcess. That doesn't work with something like "cmd". You need the full path now.

It can't return the result with ShellExecuteEx.
Logged
Matt Ashland, JRiver Media Center

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2674
Re: Feature request - ShellRun(), Before playback expression
« Reply #9 on: December 05, 2024, 10:57:28 am »

OK. Would it be possible to use SearchPathA ? Something like this:

string cmd = args[0];
if (!fileExists(cmd) && !cmd.contains('\') && !cmd.contains('/'))
{
  cmd = Win32.SearchPathA(cmd);
  if (!fileExists(cmd))
     return "ShellRun: file not found";
}
// proceed with execution
...

Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42441
  • Shoes gone again!
Re: Feature request - ShellRun(), Before playback expression
« Reply #10 on: December 05, 2024, 11:41:01 am »

Sure. Good idea.

Next build:
Changed: ShellRun searches the system for files so something like "cmd" will work.

Thanks.
Logged
Matt Ashland, JRiver Media Center

mattkhan

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4271
Re: Feature request - ShellRun(), Before playback expression
« Reply #11 on: December 05, 2024, 11:44:26 am »

Does it mean this implemented as a Windows specific function so not supported on Linux?
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42441
  • Shoes gone again!
Re: Feature request - ShellRun(), Before playback expression
« Reply #12 on: December 05, 2024, 11:46:48 am »

Just the path searching is Windows specific. I'm not certain if the run functions are implemented outside Windows.
Logged
Matt Ashland, JRiver Media Center

bob

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 13931
Re: Feature request - ShellRun(), Before playback expression
« Reply #13 on: December 05, 2024, 08:46:06 pm »

Just the path searching is Windows specific. I'm not certain if the run functions are implemented outside Windows.
It should work on Mac and linux too. If not please report. The shell shouldn't need a path if you use it.
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2674
Re: Feature request - ShellRun(), Before playback expression
« Reply #14 on: December 19, 2024, 08:54:27 am »

Pathless execution works fine on Windows :)

Can you please add a new flag?
4 = suppress output = always return an empty string, both in blocking and non-blocking mode
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42441
  • Shoes gone again!
Re: Feature request - ShellRun(), Before playback expression
« Reply #15 on: December 19, 2024, 10:21:18 am »

It only updates the output if flag 1 is set (so blocking mode). What does that hurt? I'm happy to add the option if you can help me understand. Thanks.
Logged
Matt Ashland, JRiver Media Center

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2674
Re: Feature request - ShellRun(), Before playback expression
« Reply #16 on: December 19, 2024, 11:36:34 am »

Hi Matt,

In non-blocking mode, it currently returns the executable name (arg 0). I'd prefer it to return nothing, or at most a success/fail flag (1 or 0).
In blocking mode, there are cases where the process prints out a huge dump to stdout which I really don't care about. I'm testing a script where I call ShellRun() twice to compute a field value, but I only want the output of the second call so I would like to suppress the first one:
=shellRun(app1.exe, args, 3)shellRun(app2.exe, args, 3)

I'm doing it with a workaround, but flag 4 would just be cleaner:
=if(shellRun(app1.exe, args, 3),,)shellRun(app2.exe, args, 3)
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42441
  • Shoes gone again!
Re: Feature request - ShellRun(), Before playback expression
« Reply #17 on: December 19, 2024, 11:41:35 am »

Sure. I'll add it to a build soon and please test. Thanks.
Logged
Matt Ashland, JRiver Media Center
Pages: [1]   Go Up