Author Topic: Passing arguments to MC.Run  (Read 12837 times)

espkk

  • Junior Member
  • **
  • Posts: 40
    • View Profile
Passing arguments to MC.Run
« on: April 13, 2016, 13:03:24 »
Trying to use this script:
Code: [Select]
function GetArgs()
{
  @var $args = "";
  @var $n;
  for( $n = 1; $n < $argcount; $n = $n + 1 )
  {
       $args = $args + " ";
       $args = $args + $arg($n);
  }
  return $args;
}
@var $s = GetTagValue("${mcinstallpath}") + "\\..\\";
$s = $s + $arg(0);
$s = $s + "\\";
$s = $s + $arg(0);
$s = $s + ".exe";
@var $args = GetArgs();
MC.Run CMD="{$s}" ARG="{$args}"
The problem is the script trims double quotemarks splitting "a complex argument" into 3 arguments:

Code: [Select]
run test "a complex argument"
Quote
argc = 4
C:\mc\..\test\test.exe
a
complex
argument
So I can't send filepath with spaces
how to solve this problem?

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4271
    • View Profile
    • Multi Commander
Re: Passing arguments to MC.Run
« Reply #1 on: April 13, 2016, 14:23:06 »
I'm not sure what you are trying to do..  How to you run the command, What do you want the script to do ?

Jungle

  • Contributor
  • VIP Member
  • *****
  • Posts: 510
  • Old Skull
    • View Profile
Re: Passing arguments to MC.Run
« Reply #2 on: April 13, 2016, 15:30:08 »
EsperoDrake
What about
Code: [Select]
return "\"" + $args + "\"";or
Code: [Select]
@var $args = "\"" + GetArgs() + "\"";

espkk

  • Junior Member
  • **
  • Posts: 40
    • View Profile
Re: Passing arguments to MC.Run
« Reply #3 on: April 13, 2016, 19:12:41 »
I'm not sure what you are trying to do..  How to you run the command, What do you want the script to do ?
The script should run specified app with specified arguments throw alias
The first argument is the application name which is stored in folder with the same name
I want to pass path to file with spaces which must be a single argument in double quotes
EsperoDrake
What about
Code: [Select]
return "\"" + $args + "\"";or
Code: [Select]
@var $args = "\"" + GetArgs() + "\"";
I think this would work, but I also need to pass other arguments after (or before) filepath
So, filepath must be quoted while other arguments should pass as is
Currently, MC command line deletes all double quotes ignoring \"(turns it to \, AFAIU)

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4271
    • View Profile
    • Multi Commander
Re: Passing arguments to MC.Run
« Reply #4 on: April 13, 2016, 20:48:06 »
I can't understand the script.  So I can test it. you have to give me a description on how it should be run and what should be send as parameters.

For example  when you build the $s (path to the program to run.)  you include $arg(0) twice ? is that correct. 

When you send arg to a space on the command line field you need to quote them if they have space.   [ MyScript "C:\MyFolder Ha Space\My File.Txt" -D -C ]

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4271
    • View Profile
    • Multi Commander
Re: Passing arguments to MC.Run
« Reply #5 on: April 13, 2016, 21:06:23 »
Code: [Select]
function GetArgs()
{
  @var $args = "";
  @var $n;
  @var $a;
  for( $n = 1; $n < $argcount; $n = $n + 1 )
  {
       $a = $arg($n);
       $args += ' "' + $a + '"';
  }
  return $args;
}

I change the loop a bit.  This will quote all of the args. If that was the issue
The script engine sometimes stopps appending when doing function call after anohter append.. I thinks a temp values are getting lost. Will check that.
 
Is would also be possible to write " \"" but using ' instead is easier, becuse you do not have to escape the "

espkk

  • Junior Member
  • **
  • Posts: 40
    • View Profile
Re: Passing arguments to MC.Run
« Reply #6 on: April 15, 2016, 12:05:37 »
Works perfect! Thank you
(I was afraid putting arguments in quotes would force them to be passed with quotes too, but it works as required  :) )