Hi,
this might have been asked and answered already, but I could not find an answer.
When calling a Windows batch file - e.g. "ren_myself.cmd" via double click or enter, it behaves different than calling the identical file via cmd /c ren_myself.cmd from the Total Commander command line.
This "ren_myself.cmd" is only a test for a bigger file, and here simply doing
"ren_myself.cmd":
-----------------------
ren "%~f0" "%~0.done"
It shall rename itself after successful processing.
As said, running "ren_myself.cmd" from a command window or from Total Commander prompt via "cmd /c ren_myself.cmd" - it does what is expected, it renames "ren_myself.cmd" to "ren_myself.cmd.done" - but with double click or enter - not.
So
1. why do the two methods behave different ? and
2. how can I call "ren_myself.cmd" via double click / enter - to behave like called via cmd /c ?
Can I configure anything in Total Commander to force that ?
Thanks a lot !
Best wishes,
Jo ...
Calling a Windows batch file via double click or enter behaves different than calling it via cmd /c ?!
Moderators: white, Hacker, petermad, Stefan2
- ghisler(Author)
- Site Admin
- Posts: 48083
- Joined: 2003-02-04, 09:46 UTC
- Location: Switzerland
- Contact:
Re: Calling a Windows batch file via double click or enter behaves different than calling it via cmd /c ?!
TC just calls ShellExecuteExW with the file, the rest is done by Windows. It depends on the assiciation.
If you look with regedit.exe, the association is here:
Computer\HKEY_CLASSES_ROOT\cmdfile\shell\open\command
The command is defined as follows:
"%1" %*
Maybe it helps when you change that to:
cmd.exe /c "%1" %*
If you look with regedit.exe, the association is here:
Computer\HKEY_CLASSES_ROOT\cmdfile\shell\open\command
The command is defined as follows:
"%1" %*
Maybe it helps when you change that to:
cmd.exe /c "%1" %*
Author of Total Commander
https://www.ghisler.com
https://www.ghisler.com
Re: Calling a Windows batch file via double click or enter behaves different than calling it via cmd /c ?!
2jo2h2
It is because of the syntax for the REN command:
It is not allowed to put full path before filename2 - if you do, the rename fails.
When you press Enter or doubleclick on ren_myself.cmd in TC, TC sends drive:\path\ren_myself.cmd to be executed, hence drive:\path\ren_myself.cmd is passed as %0.
If you try: cmd /c drive:\path\ren_myself.cmd it does NOT work either.
Change your batch command to:
then only the filename is passed as the second parameter and then it will also work when doubleclicking ren_myself.cmd in TC
It is because of the syntax for the REN command:
Code: Select all
REN [drive:][path]filename1 filename2
When you press Enter or doubleclick on ren_myself.cmd in TC, TC sends drive:\path\ren_myself.cmd to be executed, hence drive:\path\ren_myself.cmd is passed as %0.
If you try: cmd /c drive:\path\ren_myself.cmd it does NOT work either.
Change your batch command to:
Code: Select all
ren "%~f0" "%~n0%~x0.done"
Last edited by petermad on 2019-03-24, 23:37 UTC, edited 1 time in total.
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
Re: Calling a Windows batch file via double click or enter behaves different than calling it via cmd /c ?!
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64
Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64
Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
Re: Calling a Windows batch file via double click or enter behaves different than calling it via cmd /c ?!
2Dalai
You are right of course - Thanks"%~nx0.done" should do the same.
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
Re: Calling a Windows batch file via double click or enter behaves different than calling it via cmd /c ?!
You all are great - thanks for your super fast and very help replies !
The corrected ren command works perfectly !
Again, thank you so much !!
The corrected ren command works perfectly !
Again, thank you so much !!