This forum uses cookies. Click X button to hide this message. What is stored? 
Total Commander Forum Index Total Commander
Forum - Public Discussion and Support
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Error argument in BAT-file from Button

 
Post new topic   Reply to topic    Total Commander Forum Index -> TC8.5x bug reports (English) Printable version
View previous topic :: View next topic  
Author Message
Ciber SLasH
Junior Member
Junior Member


Joined: 25 Apr 2013
Posts: 7

PostPosted: Mon Jun 13, 2016 6:52 am    Post subject: Error argument in BAT-file from Button Reply with quote

Hi all!
Button:
Code:
TOTALCMD#BAR#DATA
cmd.exe /K
"%%Commander_Path%%\Scripts\ReadCL.bat" "D:\Soft\#CMD tools\MTEE\mtee.bat"
%Commander_Path%\WCMICONS.DLL,74
ReadCL


-1

ReadCL.bat:
Code:
@echo off
echo [ %~nx0 :: Arguments ]
echo 1-9: %1 %2 %3 %4 %5 %6 %7 %8 %9
echo --------------------------------------------------------------------------------
echo %% 1: %1
echo %% 2: %2
echo %% 3: %3
echo %% 4: %4
echo %% 5: %5
echo %% 6: %6
echo %% 7: %7
echo %% 8: %8
echo %% 9: %9
pause

Press button & have error.
also have error:
Code:
TOTALCMD#BAR#DATA
cmd.exe /K
"%%Commander_Path%%\Scripts\ReadCL.bat" "1"
%Commander_Path%\WCMICONS.DLL,74
ReadCL


-1
Back to top
View user's profile Send private message
Dalai
Power Member
Power Member


Joined: 28 Jan 2005
Posts: 5597
Location: Meiningen (Südthüringen)

PostPosted: Mon Jun 13, 2016 7:10 am    Post subject: Reply with quote

That's not TC's fault, it's the CMD syntax you have to follow here. Just quote to whole parameters field to make it work:
Code:
TOTALCMD#BAR#DATA
cmd.exe /K
""%%Commander_Path%%\Scripts\ReadCL.bat" "D:\Soft\#CMD tools\MTEE\mtee.bat""
%Commander_Path%\WCMICONS.DLL,74
ReadCL


-1
Yes, it may look weird, but that's how it works.

Regards
Dalai
_________________
#101164 Personal licence
Athlon X4 880K, 16 GiB RAM, Gigabyte F2A88X-D3HP, Win7 x64

Plugins: Services2, Startups
Back to top
View user's profile Send private message Send e-mail
Ciber SLasH
Junior Member
Junior Member


Joined: 25 Apr 2013
Posts: 7

PostPosted: Mon Jun 13, 2016 9:20 am    Post subject: Reply with quote

Double quote hack not good idea.
Arguments maybe from %P%N.
I make JScript
Run.js
Code:
/*
[ For execute EXE|CMD|BAT ]
@name   Run.js
@ver   1.00
@author   Ciber SLasH
@cDate   2013-11-22
@mDate   2016-06-13
*/
//------------------------------------------------------------------------------
var DEBUG = 0;
var MAXIMIZE = 0;
//------------------------------------------------------------------------------
SW_SHOWMAXIMIZED = 2;
WshShell = WScript.CreateObject('WScript.Shell');
//------------------------------------------------------------------------------
if (WScript.Arguments.length == 0) {
   showMsgEx('Empty arguments!', 'warning');
   Quit(-1);
}
//------------------------------------------------------------------------------
var cmdLine = "";
for (var i = 0; i < WScript.Arguments.length; i++) {
   var param = WScript.Arguments.Item(i);
   if (param.toUpperCase() == '/MAX') {
      MAXIMIZE = 1;
   } else if (param.toUpperCase() == '/DEBUG') {
      DEBUG = 1;
   } else {
      if (/%\w+%/.test(param))   param = WshShell.ExpandEnvironmentStrings(param);
      if (param.substr(0,1) != '"' && param.indexOf("\\") != -1)   param = '"'+param+'"';
      cmdLine += param + ' ';
   }
}
cmdLine = cmdLine.slice(0, -1);
//------------------------------------------------------------------------------
if (DEBUG == 1)
   showMsgEx('cmdLine:\n\n' + cmdLine);
else {
   if (MAXIMIZE == 0)
      WshShell.Run(cmdLine);
   else
      WshShell.Run(cmdLine, SW_SHOWMAXIMIZED);
}
//------------------------------------------------------------------------------
Quit(0);
////////////////////////////////////////////////////////////////////////////////
//==[ Funcs ]===================================================================
////////////////////////////////////////////////////////////////////////////////
//--[ Quit from script ]--------------------------------------------------------
function Quit(exitCode) {
   FreeObjects();
   WScript.Quit(exitCode);
}
//--[ Free objects from memory ]------------------------------------------------
function FreeObjects() {
   if (typeof(FSO) != 'undefined')         FSO.Quit;
   if (typeof(WshShell) != 'undefined')   WshShell.Quit;
}
/*
[ Show extended message ]
@param1 msg (String)      - message
*@param2 msgType (String)   - message type: error|warning (default: "info")
*@param3 caption (String)   - message caption
--------------------------------------------------------------------------------
Used "WshShell.Popup"
*/
function showMsgEx(msg, msgType, caption) {
// Consts button
var MB_OK = 0x0;
// Consts icons
var MB_ICONERROR = 0x10;
var MB_ICONWARNING = 0x30;
var MB_ICONINFORMATION = 0x40;
   msgType = msgType ? msgType.toUpperCase() : '';
   caption = caption ? ': '+caption : '';
   caption = WScript.ScriptName+' ]' + caption;
   switch (msgType) {
      case 'ERROR':
         msgType = MB_ICONERROR;
         caption = '[ ERROR :: '+caption;
         break;
      case 'WARNING':
         msgType = MB_ICONWARNING;
         caption = '[ Warning :: '+caption;
         break;
      default:
         msgType = MB_ICONINFORMATION;
         caption = '[ Info :: '+caption;
         break;
   }
   WshShell.Popup(msg, 0, caption, MB_OK | msgType);
}

and make button:
Code:
TOTALCMD#BAR#DATA
Run.js
?"%%Commander_Path%%\..\#CMD tools\MTEE\mtee.bat" %P%N
%Commander_EXE%,2
bat::run -> MTEE
%Commander_Path%\Scripts\

-1
Back to top
View user's profile Send private message
Dalai
Power Member
Power Member


Joined: 28 Jan 2005
Posts: 5597
Location: Meiningen (Südthüringen)

PostPosted: Mon Jun 13, 2016 9:49 am    Post subject: Reply with quote

Ciber SLasH wrote:
Double quote hack not good idea.

That's no hack at all. It's just the way CMD expects its arguments. Look it up by typing CMD /? in a CMD window.

Quote:
Arguments maybe from %P%N.

So? It works the same way, regardless of TC quoting %P%N or not. If you need to remove the quotes in the batch, just use %~1 through %~9; the same applies to for-loop variables, i.e. %%i doesn't remove quotes around the contents of i while %%~i removes them.

Regards
Dalai
_________________
#101164 Personal licence
Athlon X4 880K, 16 GiB RAM, Gigabyte F2A88X-D3HP, Win7 x64

Plugins: Services2, Startups
Back to top
View user's profile Send private message Send e-mail
Ciber SLasH
Junior Member
Junior Member


Joined: 25 Apr 2013
Posts: 7

PostPosted: Mon Jun 13, 2016 9:58 am    Post subject: Reply with quote

Button1:
Code:
TOTALCMD#BAR#DATA
cmd.exe /K
"%%Commander_Path%%\Scripts\ReadCL.bat" %P%N
%Commander_EXE%,3
Test command
%Commander_Path%\Scripts\

-1

Button2:
Code:
TOTALCMD#BAR#DATA
cmd.exe /K
"%%Commander_Path%%\Scripts\ReadCL.bat" "%P%N"
%Commander_EXE%,3
Test command
%Commander_Path%\Scripts\

-1

both - error.
Press ButtonX on path "D:\Soft\#CMD tools\MTEE\mtee.bat"
ReadCL.bat - empty.
Back to top
View user's profile Send private message
Dalai
Power Member
Power Member


Joined: 28 Jan 2005
Posts: 5597
Location: Meiningen (Südthüringen)

PostPosted: Mon Jun 13, 2016 10:06 am    Post subject: Reply with quote

I already said that you need to quote the whole parameter field. If you do, %P%N works as well as any other parameter.

Note that you must not quote %P%N, TC does that by itself if they contain spaces.

Regards
Dalai
_________________
#101164 Personal licence
Athlon X4 880K, 16 GiB RAM, Gigabyte F2A88X-D3HP, Win7 x64

Plugins: Services2, Startups
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Total Commander Forum Index -> TC8.5x bug reports (English) All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Impressum: This site is maintained by Ghisler Software GmbH

Using phpBB © 2001-2005 phpBB Group