INTERACT FORUM

Please login or register.

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

Author Topic: Passing Multiple Commands on Command Line  (Read 6759 times)

edbro

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 734
Passing Multiple Commands on Command Line
« on: September 25, 2006, 12:40:34 pm »

How do I pass mulitple commands to MC11.exe? I have MC open in Standard View but I want to open an M3u playlist in Minime mode. I have tried using:
Code: [Select]
'c:\windows\system32\mc11.exe' /Mode Minime /playreplace but that doesn't accept the playlist. It seems I can only pass one command parameter in the command line?
Code: [Select]
mc11.exe /playreplace also works but without switching to Minime mode.

Is there a way to construct this command line to do both? I am using another program to pass the m3u playlist to MC.
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42323
  • Shoes gone again!
Re: Passing Multiple Commands on Command Line
« Reply #1 on: September 25, 2006, 01:41:53 pm »

Make a batch file that sends the commands one after the other.

The launcher (MC11.exe) was designed to be very light-weight, so there'll be little performance difference from calling it mulitple times.
Logged
Matt Ashland, JRiver Media Center

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: Passing Multiple Commands on Command Line
« Reply #2 on: September 25, 2006, 03:32:06 pm »

If you don't want the command prompt window to appear because of your BAT file running, you can use my instructions in this thread to build a WSH script instead (or at least call your BAT file from within the WSH script to keep the cmd window hidden):

http://yabb.jriver.com/interact/index.php?topic=35576.msg243562#msg243562
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

edbro

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 734
Re: Passing Multiple Commands on Command Line
« Reply #3 on: September 25, 2006, 03:51:31 pm »

If you don't want the command prompt window to appear because of your BAT file running, you can use my instructions in this thread to build a WSH script instead
Thanks to both of you. The batch file works.
Glynor, I'm sure the script would work but I already have a way to hide the command window. See first line of bat:
Code: [Select]
%WINDIR%\system32\cmdow @ /HID
%WINDIR%\system32\mc11.exe /playreplace %1
%WINDIR%\system32\mc11.exe /mode minime

The program cmdow.exe is a freeware utility which will hide the command window. WSH too scary for me!
Logged

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: Passing Multiple Commands on Command Line
« Reply #4 on: September 25, 2006, 03:59:44 pm »

Does the command window still flash by for a second but then hide, or does it never appear at all?

BTW, as I stated later on in the thread, you don't need to do any WSH stuff at all to use my method.  Just steal the script I already wrote and call your BAT from it...

See here:  http://yabb.jriver.com/interact/index.php?topic=35576.msg244144#msg244144

Of course, if you're happy with your way, then what's the point?   ;)
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

edbro

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 734
Re: Passing Multiple Commands on Command Line
« Reply #5 on: September 25, 2006, 04:31:39 pm »

Does the command window still flash by for a second but then hide, or does it never appear at all?
Yes, it does  :(

Quote
BTW, as I stated later on in the thread, you don't need to do any WSH stuff at all to use my method.  Just steal the script I already wrote and call your BAT from it...
Okay, I tried it but I get an error message. This is the modified script:
Code: [Select]
<package>
   <job id="vbs">
      <script language="VBScript">
         set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "C:\Program Files\J River\mc11.bat", 0, False
      </script>
   </job>
</package>
That give me an error popup stating:
Code: [Select]
Script: C:\program files\j river\mc11.wsf
line: 5
char: 2
Error: The system cannot find the file specified
Code: 80070002
Source: (null)

So, what did I do wrong? And, does the argument (the m3u file) get passed to the script file and then to the bat?
Logged

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: Passing Multiple Commands on Command Line
« Reply #6 on: September 25, 2006, 05:12:06 pm »

Well... A couple of things.

First of all, does "C:\Program Files\J River\mc11.bat" exist?  Typically that error message happens when the program you're trying to call with the .Run command doesn't exist.

Make sure you didn't spell anything wrong, and that it isn't called "mc11 .bat" or anything like that.

Secondly, it could be because the %1 isn't in the WSH script.  You want to call the command line in the "" just like you would call the bat itself.  This means you'd probably want to use:

Code: [Select]
I was wrong, see below
I'll have to make sure that %1 actually works.... Gimme a sec.
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: Passing Multiple Commands on Command Line
« Reply #7 on: September 25, 2006, 05:34:43 pm »

Ok... It doesn't.  To access the command line parameters from within a shell script, you have to use a different variable than "%1".  Still construct your BAT file the same way, using the "%1" anywhere you would, but in the WSH script, you need to call it using the special WScript.Arguments.Item(x) variable.

Because the the special variable is based on an object called a "collection" which are Zero based, you want to use 0 in the parenthesis (replacing X in the above line) to reference command line argument #1, and 1 to reference #2, and 2 to reference #3, and so on and so forth.  If this doesn't make sense, just understand that when referring to the arguments in WSH scripts, argument one is really called zero, two is called one, three is called two, and so on and so forth.

So, to pass the first command line argument to a BAT script that uses only 1 argument you'd use:

Code: [Select]
<package>
   <job id="vbs">
      <script language="VBScript">
         set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "C:\temp\scripts\test\test_bat.bat " & WScript.Arguments.Item(0), 0, False
      </script>
   </job>
</package>

Make sure to note the space before the " after test_bat.bat in the above example.  This is required or the command line "sent" would all run together.  If you needed two command line arguments, you could use:

Code: [Select]
<package>
   <job id="vbs">
      <script language="VBScript">
         set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "C:\temp\scripts\test\test_bat.bat " & WScript.Arguments.Item(0) & " " & WScript.Arguments.Item(1), 0, False
      </script>
   </job>
</package>

And so on.  (In the above example, the & " " &  is needed so that there will be a space separating the arguments sent to the batch file.)
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: Passing Multiple Commands on Command Line
« Reply #8 on: September 25, 2006, 05:42:08 pm »

Again.  This looks scarier than it is.  For 99.9% of the scripts you'd run from within MC, you'll only have 1 command line argument.  That is, the file's name (that %1 in your BAT file).  Whatever comes after the WshShell.Run command in the WSH script is going to be run, just as it would be if you went to a command line prompt and typed it yourself.

If you want to send that one argument along (the filename usually), you need to use the example #1 above.  Make sure of:

1) you put the right path to your BAT script.
2) after the path to your BAT script, make sure to put a space before the closing " symbol.

Also, one last thing.  If you ever use the WScript.Arguments.Item(0) variable in a script, and then run that script without giving it that argument (by just double clicking it for example), you'll get a subscript out of range error.  It's really hard to explain why it's called that, but suffice to say that error means that there was no Argument 1 and your script tried to use it.

If you think this might be an issue (it shouldn't for most MC scripts) then you can test for it if you want, and if you want to get a little more complicated...
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

edbro

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 734
Re: Passing Multiple Commands on Command Line
« Reply #9 on: September 25, 2006, 06:14:29 pm »

Thanks Glynor,
No need for the batch file now. I do it all with the script.
Code: [Select]
<package>
   <job id="vbs">
      <script language="VBScript">
         set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "C:\windows\system32\mc11.exe /playreplace " & WScript.Arguments.Item(0)
WScript.Sleep(500)
WshShell.Run "C:\windows\system32\mc11.exe /mode minime "
      </script>
   </job>
</package>

And, yes it was that extra space that was originally messing me up.
Logged

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: Passing Multiple Commands on Command Line
« Reply #10 on: September 25, 2006, 06:46:54 pm »

There you go!

See... Not so scary after all.  BTW: That WScript.Sleep command was the one big reason I started figuring out WSH scripts in the first place.  It's super handy!
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

slipknot

  • Galactic Citizen
  • ****
  • Posts: 255
Re: Passing Multiple Commands on Command Line
« Reply #11 on: September 26, 2006, 03:26:08 am »

It would be great to have an Mc11.exe command to start MC AND start playback of the playing now playlist.

I know I can set MC to start playback on startup, but I'd like to be able to start MC without starting playback for normal use and be able to do the start/play from my remote control using MC11.
Logged
Pages: [1]   Go Up