passing selected files as parameters to command line

English support forum

Moderators: Hacker, petermad, Stefan2, white

Post Reply
sujanlal
Junior Member
Junior Member
Posts: 26
Joined: 2007-12-08, 08:57 UTC

passing selected files as parameters to command line

Post by *sujanlal »

I have command line as follows.

matlab -nodisplay -nodesktop -nosplash -nojvm -r "nccmp('d:\RPP\new.nc','d:\RPP\old.nc'),quit" -logfile d:\logfile.log


I would like to run this command with button bar or hot key. Is there any way to pass argument 'd:\RPP\new.nc' as left selected file and 'd:\RPP\old.nc' as right selected file in above command?

Thank you very much.
User avatar
Stefan2
Power Member
Power Member
Posts: 4281
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Post by *Stefan2 »

Yes.
In the button bar dialog press the F1 key and read the help:

%P causes the source path to be inserted into the command line, including a backslash (\) at the end.
%N places the filename under the cursor into the command line.
%T inserts the current target path.
%M places the current filename in the target directory into the command line.

And many more...


So I would insert %P%N and %T%M

- - -

To create an button, right click at the button bar and chose "Change..." and then "Add"

The normal way is to use "the executable as command" and "the rest as parameter".


- - -

To assign a shortcut (hot key), write your command into a file TotalCommander\usercmd.ini.
Then utilize "Configuration > Options > Misc." to assign the hot key.

You can also do this both via an TC dialog:
* open "Configuration > Options > Misc."
* choose any key (just temporarily for creating the command, or chose one to keep)
* click on magnifying glass icon
* select "usercmd.ini" on left side
If you have no usercmd.ini on the list, create the file first with this name under your TC directory.
* New > enter em_YourTermHere (<< the name of your command, “em_” is mandatory) > OK
* type in your own, or select a command on right side
* click on OK
* click on OK

.
sujanlal
Junior Member
Junior Member
Posts: 26
Joined: 2007-12-08, 08:57 UTC

Post by *sujanlal »

Thank you Stefan 2 for the response.

I know how to create button and short-cut. I also know how to use parameters in the command with simple syntax like below
program.exe param1 param2

But my command syntax is different. My problem is how to actually replace the commands in the bold with parameters

matlab -r "nccmp('d:\RPP\new.nc','d:\RPP\old.nc')
User avatar
ts4242
Power Member
Power Member
Posts: 2081
Joined: 2004-02-02, 20:08 UTC
Contact:

Post by *ts4242 »

sujanlal wrote:My problem is how to actually replace the commands in the bold with parameters

matlab -r "nccmp('d:\RPP\new.nc','d:\RPP\old.nc')

Code: Select all

matlab -r "nccmp('%P%N','%T%M')
User avatar
Stefan2
Power Member
Power Member
Posts: 4281
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Post by *Stefan2 »

Ah, what we have forgotten, Taher, is to tell the user

he needs to have the "d:\RPP\" folder open in both panels.

Then he needs to select "d:\RPP\new.nc" on the left and "d:\RPP\old.nc" on the right. (or vice versa)


With TC we can't simple select two files in one panel for this kind of work.
For that, we would need a script and the TC-Parameter %L

%L create a list file in the TEMP directory with the names of the selected files


EDIT:
in the meantime I have crafted an possible such script:
EDIT2:
changed script to v0.02 for to allow selection on both panels too.
Now you can run this script with either TC para '%L' (or such, see help)
or with TC paras '%P%N %T%M' (note the space between %P%N and %T%M)

%L is used for two selections in ONE pane.
%P%N is the selected item in active pane, %T%M is the selected item in target (inactive) pane.

 

Code: Select all

'ForTwoSelectedDo.vbs, VBS Script by Stefan, 2014-07-23, v0.02
'Purpose:  Select TWO files or folder in ONE or both panels, then execute this script 
'          to run your application with the two selected files or folders as parameter.
'#####################################################################################
'#####################################################################################
'#   _____  _                 _____             _       
'#  |_   _|| |               /  __ \           | |      
'#    | |  | |__    ___      | /  \/  ___    __| |  ___ 
'#    | |  | '_ \  / _ \     | |     / _ \  / _` | / _ \
'#    | |  | | | ||  __/     | \__/\| (_) || (_| ||  __/
'#    \_/  |_| |_| \___|      \____/ \___/  \__,_| \___|
'#    __    _               _  _          _                       _    __  
'#   / /   | |             ( )| |        | |                     | |   \ \ 
'#  | |  __| |  ___   _ __ |/ | |_       | |_  ___   _   _   ___ | |__  | |
'#  | | / _` | / _ \ | '_ \   | __|      | __|/ _ \ | | | | / __|| '_ \ | |
'#  | || (_| || (_) || | | |  | |_       | |_| (_) || |_| || (__ | | | || |
'#  | | \__,_| \___/ |_| |_|   \__|       \__|\___/  \__,_| \___||_| |_|| |
'#   \_\                                                               /_/ 
'#                                                                         
'#####################################################################################
'#####################################################################################
Set FSO        = CreateObject("Scripting.FileSystemObject")
Set WSC        = CreateObject("WScript.Shell")
strTCFolder    = WSC.ExpandEnvironmentStrings("%Commander_Path%")
intTCParaCount = Wscript.arguments.Count
If(intTCParaCount = 1 ) Then
    'Parameter: %L
    strDebugMsg  = "One para found: '%L'"
    intFileCounter = 0
    strTCTempList = Wscript.arguments.Item(0) ' Get the TC parameter
      Set oTextStream = FSO.OpenTextFile(strTCTempList, 1)
      Do Until oTextStream.AtEndOfStream
         intFileCounter = intFileCounter + 1
         If (intFileCounter = 1) Then strFullName1 = oTextStream.ReadLine
         If (intFileCounter = 2) Then strFullName2 = oTextStream.ReadLine : Exit Do
      Loop
      oTextStream.Close
ElseIf(intTCParaCount = 2 ) Then
      'Parameter: %P%N %T%M
      strDebugMsg  = "Two para found: '%P%N %T%M'"
      strFullName1 = Wscript.arguments.Item(0)
      strFullName2 = Wscript.arguments.Item(1)
Else
        WScript.Echo "Parameter wrong. Do you run this script with Total Commander " _
                    & "and set the parameter, either to '%L', or to '%P%N %T%M'?" 
        WScript.Quit
End If

'#####################################################################################
'#####################################################################################
'#   _   _                    _____        _    _    _                    
'#  | | | |                  /  ___|      | |  | |  (_)                   
'#  | | | | ___   ___  _ __  \ `--.   ___ | |_ | |_  _  _ __    __ _  ___ 
'#  | | | |/ __| / _ \| '__|  `--. \ / _ \| __|| __|| || '_ \  / _` |/ __|
'#  | |_| |\__ \|  __/| |    /\__/ /|  __/| |_ | |_ | || | | || (_| |\__ \
'#   \___/ |___/ \___||_|    \____/  \___| \__| \__||_||_| |_| \__, ||___/
'#                                                              __/ |     
'#                                                             |___/      
'#####################################################################################
'#####################################################################################
'// Do your work with the two files:
'Explanation: utilize Windows Script Host's Run Method to run your app 
'(http://msdn.microsoft.com/en-us/library/d5fk67ky%28v=vs.84%29.aspx)

'Debug (remove this after first tests):
Msgbox strDebugMsg & vbCRLF & "Will work with this files:" & vbCRLF & strFullName1 & vbCRLF & strFullName2

'   Run(strCommand, [intWindowStyle=1], [bWaitOnReturn=false])
'simple test with DOS-Box (remove this after first tests):
'WSC.run "cmd /k ECHO "&chr(34)&strFullName1&chr(34)&" & ECHO "&chr(34)&strFullName2&chr(34)&" & PAUSE"

'run an executable with the selected files as parameter:
'WSC.run  strTCFolder & "\TOOLs\BeyondCompare251\BC2.exe " & chr(34) & strFullName1 & chr(34) & " " & chr(34) & strFullName2 & chr(34)

'########################################################
'TC button:
'Command:  "%COMMANDER_PATH%\VBS\ForTwoSelectedDo.vbs"
'Parameter: %L   (OR parameter: %P%N %T%M)
'Icon:      C:\Windows\System32\WScript.exe,2
'Tool tip:  For Two Selected Files Do
'--------------------------------------------
Last edited by Stefan2 on 2014-07-24, 07:28 UTC, edited 2 times in total.
sujanlal
Junior Member
Junior Member
Posts: 26
Joined: 2007-12-08, 08:57 UTC

Post by *sujanlal »

Actually I am comparing new.nc in left panel and old.nc in right panel as below.

matlab -r "nccmp('D:\LeftPanel\old.nc','D:\RightPanel\new.nc')"
matlab -r "nccmp('%P%N','%T%M')
Using above code, it did not pass the selected files to commands (output from matlab: COMPARING netcdf files: %P%N <> %T%M).

Did I miss something?
User avatar
Stefan2
Power Member
Power Member
Posts: 4281
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Post by *Stefan2 »

sujanlal wrote:
matlab -r "nccmp('%P%N','%T%M')
it did not pass the selected files to commands

Did I miss something?
Stefan2 wrote:
The normal way is to use "the executable as command" and "the rest as parameter".
cmd: matlab
para: -r "nccmp('%P%N','%T%M'


More behind F1 key.


Sometimes, you have to try which part belongs to para, and which to cmd.


 
sujanlal
Junior Member
Junior Member
Posts: 26
Joined: 2007-12-08, 08:57 UTC

Post by *sujanlal »

Thanks. This is what I want.

At the beginning I thought it is not possible. What a great tool!

That's why I love Total commander and have been using since 2002.
Post Reply