passing selected files as parameters to command line
Moderators: Hacker, petermad, Stefan2, white
passing selected files as parameters to command line
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.
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.
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:
.
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
.
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')
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')
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')
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.
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.
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')"
Did I miss something?
matlab -r "nccmp('D:\LeftPanel\old.nc','D:\RightPanel\new.nc')"
Using above code, it did not pass the selected files to commands (output from matlab: COMPARING netcdf files: %P%N <> %T%M).matlab -r "nccmp('%P%N','%T%M')
Did I miss something?
sujanlal wrote:it did not pass the selected files to commandsmatlab -r "nccmp('%P%N','%T%M')
Did I miss something?
cmd: matlabStefan2 wrote:
The normal way is to use "the executable as command" and "the rest as parameter".
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.