Author Topic: Relative path  (Read 11361 times)

espkk

  • Junior Member
  • **
  • Posts: 40
    • View Profile
Relative path
« on: April 05, 2016, 09:57:09 »
How to use relative paths in MC cmd? Trying to exec ..\npp\notepad++.exe has no effect. cd ..\npp\ and running directly from cmd.exe folder works fine

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4271
    • View Profile
    • Multi Commander
Re: Relative path
« Reply #1 on: April 05, 2016, 16:42:21 »
It depends on what command type you use.

You must use a Tag or command that expand to ful path becuse depending on command the how it is launch working folder is the path of the current viewed folder and not MC exe path

If the command is of Customcommand type then you can use any of the following Multitags
http://multicommander.com/docs/multitags

espkk

  • Junior Member
  • **
  • Posts: 40
    • View Profile
Re: Relative path
« Reply #2 on: April 05, 2016, 23:47:07 »
Thank you for the link. It solves the problem, but I still have a question
Is it possible to use relative path in MC address bar/alias(AFAIU they works the similar way)? I mean, is it possible to run X:\Folder1\file.exe from X:\Folder2\ opened in current tab without using scripts or sequence "cd+filename". It may look weird though sometimes it's useful

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4271
    • View Profile
    • Multi Commander
Re: Relative path
« Reply #3 on: April 06, 2016, 07:53:11 »
relative to folder used to work from the commandline field. But MS changed how a API worked because of security issues. So it does not automatically work anymore.
You can do tricks with script i believe to make it kind of work by making the script that is run then launch the parameter as a command.  "r ..\do.exe"

I have on my todo list to add some kind of workaround. I will see of I can get around to do that..

espkk

  • Junior Member
  • **
  • Posts: 40
    • View Profile
Re: Relative path
« Reply #4 on: April 06, 2016, 10:42:17 »
Thank you for your answer.
It's not perfect way but works for me:
Code: [Select]
function GetArgs()
{
  @var $args = "";
  @var $n = 0;
  for( $n = 0; $n < $argcount; $n = $n + 1 )
  {
    if( $n > 0 )
    {
       $args = $args + " ";
    }
    $args = $args + $arg($n);
  }
  return $args;
}
@var $exec = GetTagValue("${sourcepath}") + GetArgs();
MC.Run CMD="{$exec}";

It seems that MC.Run base path equils ${mcinstallpath} + "\", is this always the truth? Also, I have confused why this code works:
Code: [Select]
@var $exec = GetTagValue("${mcinstallpath}") + "\..\app\app.exe";
MC.Run CMD="{$exec}";
and this code also works:
Code: [Select]
MC.Run CMD=" "..\app\app.exe";and this is not:
Code: [Select]
MC.Run CMD= GetTagValue("${mcinstallpath}") + "\..\app\app.exe";What's the problem?

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4271
    • View Profile
    • Multi Commander
Re: Relative path
« Reply #5 on: April 06, 2016, 15:39:17 »
Code: [Select]
MC.Run CMD= GetTagValue("${mcinstallpath}") + "\..\app\app.exe";What's the problem?

GetTagValue() are a MultiScript function and can only be called from that command type. not from CustomCommand

However I do know it can be confusing because a MultiScript can also call CustomCommands. But when doing embedded CustomCommand calls from MultiScript,  you can not use  MultiScript functions on that line. that line is run but the custom command engine.


espkk

  • Junior Member
  • **
  • Posts: 40
    • View Profile
Re: Relative path
« Reply #6 on: April 07, 2016, 12:36:06 »
Quote
GetTagValue() are a MultiScript function and can only be called from that command type. not from CustomCommand
Ofc I called it in multiscript
Quote
However I do know it can be confusing because a MultiScript can also call CustomCommands. But when doing embedded CustomCommand calls from MultiScript,  you can not use  MultiScript functions on that line. that line is run but the custom command engine.
Didn't get it  :( You mean the whole line runs in single engine?

Answer pls
Quote
It seems that MC.Run base path equils ${mcinstallpath} + "\", is this always the truth?
can I rely on that?

P.S. can you explain why this works:
Code: [Select]
MC.Run CMD="folder/file.exe";and this is not:
Code: [Select]
@var $cmd="folder/file.exe";
MC.Run CMD=$cmd;
this also works
Code: [Select]
@var $cmd="folder/file.exe";
MC.Run CMD="{$cmd}";
and this SOMETIMES works and sometimes throws an error(Out of memory error in program, reading NULL pointer in debugger):
Code: [Select]
@var $cmd="folder/file.exe";
MC.Run CMD={$cmd};

Also docs describe
Quote
Escape sequence consists of a backslash (\) followed by a letter. Each Escape sequence is regarded as a single character.
If you want an actual backslash in your constant string you need to write "\\". This will translate into "\".
but path with single backslashes in double quotes works well?

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4271
    • View Profile
    • Multi Commander
Re: Relative path
« Reply #7 on: April 07, 2016, 13:31:42 »
Quote
GetTagValue() are a MultiScript function and can only be called from that command type. not from CustomCommand
Ofc I called it in multiscript
Quote
However I do know it can be confusing because a MultiScript can also call CustomCommands. But when doing embedded CustomCommand calls from MultiScript,  you can not use  MultiScript functions on that line. that line is run but the custom command engine.
Didn't get it  :( You mean the whole line runs in single engine?
There are type main type of Script CustomCommands and MultiScript..

CustomCommand are for simple 1 line command that maps often direly to commands in MC. Think of them as they connect to the UI layer in MC.
They are often used when you want to call a command you see in the menu or similar but with a new set of parameters. or similar..

MultiScript are the advanced engine where you can write loops, conditions, have variables and stuff.. function called into MC from MultiScript often connect to the core in MC, without activating the UI.

When the MultiScript engine see a CustomCommand, It sends that line to be evaluated by the customcommand engine. Since MultiScript engine do not know what to do with it. It does not really fit into the its scripting language.  You can enter some { } tags around variables that will be evaulated by the MultiScript engine before sending it off to CC. but only for variables.  eg  PATH="{$varPath}"

It seems that MC.Run base path equils ${mcinstallpath} + "\", is this always the truth?
can I rely on that?
Not sure. I think it depends, Safe way is to use $mcinstallpath then it cant go wrong

P.S. can you explain why this works:
Code: [Select]
MC.Run CMD="folder/file.exe";and this is not:
Code: [Select]
@var $cmd="folder/file.exe";
MC.Run CMD=$cmd;
CustomCommand do not support parameters.. if it is run from a MultiScript you need to put {}around it so that the variable is evaulated for it is sent to the custom command engine.

Quote
but path with single backslashes in double quotes works well?
It only work if it fails to translate a escape character.. so you have have a path that is "SomePath\newpath" it will fail since \n is a escape character.
So use single quote.

espkk

  • Junior Member
  • **
  • Posts: 40
    • View Profile
Re: Relative path
« Reply #8 on: April 07, 2016, 13:48:56 »
Thank you! Got it

espkk

  • Junior Member
  • **
  • Posts: 40
    • View Profile
Re: Relative path
« Reply #9 on: April 11, 2016, 15:56:47 »
Quote
but path with single backslashes in double quotes works well?
It only work if it fails to translate a escape character.. so you have have a path that is "SomePath\newpath" it will fail since \n is a escape character.
So use single quote.
MC.Run CMD="..\npp\notepad++.exe"
still works well
This is not a complaint but it looks strange  :)

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4271
    • View Profile
    • Multi Commander
Re: Relative path
« Reply #10 on: April 11, 2016, 17:07:09 »
You are still mixing the script types.. :)

MC.Run is a CustomCommand.. not a MultiScript.    only MultiScript support escaping of characters

ex
Code: [Select]
@var $str = "Line 1\nLine 2\n"Line3\n\tLine4 with tab";