AskParam: Asks for command-line parameters via GUI dialog

Discuss and announce Total Commander plugins, addons and other useful tools here, both their usage and their development.

Moderators: white, Hacker, petermad, Stefan2

Post Reply
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

AskParam 1.0.6.112:
+ 64-bit version
+ resizeable window width
+ initial width may be set with /v parameter
tyee
Junior Member
Junior Member
Posts: 3
Joined: 2014-07-06, 17:20 UTC

Post by *tyee »

Very nice app, thanks. I have a need for it to stay open after clicking the button to run the command line program. I test out different video encodings and this app allows me to select from them with the drop down list items, but I have to restart all over again to test the next settings. Is it possible to prevent it from closing so I can reselect list box items again?
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

AskParam can't restart itself but you can do it from batch file, e.g.:

Code: Select all

@echo off
if -%1==- goto start_askparam
rem Here you process parameters %1, %2 etc and call encoders
if -%1==-encoder1 start "" "X:\Path\To\encoder1.exe" parameters
...

:start_askparam
rem Here you start AskParam that will then call this batch back
start "" "X:\Path\To\AskParam.exe" choice parameters "%~0" %%1 %%2 %%3 %%4 ...
Just run this batch and it will start AskParam.
tyee
Junior Member
Junior Member
Posts: 3
Joined: 2014-07-06, 17:20 UTC

Post by *tyee »

I don't quite follow that totally. Here is my current command line which I am already running from a batch file which is called "RunEncoder.bat" -

Code: Select all

AskParam64 /v600 /c"Encoder" /t"long list of my settings" /p"Select Mode:" "encode.bat" %%1
So how do I restart "RunEncoder.bat" after "encode.bat" is completed?

I made "RunEncoder.bat" so I can just double click to start everything instead of going into command line mode.

Update - I think I can do what I want by just using the /w switch and adding ":start" label at top of 'RunEncoder.bat" and "Goto start" command at bottom, yes? I will try it.

Update2 - Yes, it works very well.

One thing that would be nice is for Ask Param.exe to save my first parameter the next time it starts. Is this possible somehow? Hmm...I will try setting it as a variable and see.
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

Yes, environment variable should work fine!

Code: Select all

@echo off
if -%1==- (
	set encoder_params=long list of my settings
	goto start_askparam
)
set encoder_params=%*
start "" /wait "encoder.exe" %encoder_params%

:start_askparam
start "" "AskParam64.exe" /v600 /c"Encoder" /t"%encoder_params%" /p"Select Mode:" "%~0" %%1
So, if there are no parameters (first launch), it uses default values "long list of my settings", then it calls encoder and waits for its termination. Then it starts AskParam which will then call batch again with selected options.
When batch receives some arguments (second and further launches), it uses them instead of default values, calls encoder etc.

You don't need any loops in batch at all: batch calls AskParam, it calls batch back - there is a loop already. And only in such case your batch knows what you've chosen in AskParam.
Also keep in mind that you can add /s0 AskParam parameter to hide both console window and taskbar button or /s2 to minimize window.
tyee
Junior Member
Junior Member
Posts: 3
Joined: 2014-07-06, 17:20 UTC

Post by *tyee »

Ok, looks nearly perfect but I have removed a line and added a /p to show the filename I'm working on. I want to go directly into AskParam first if there is no %1, so here it is -

Code: Select all

@echo off
if -%1==- (
   goto start_askparam
)
set encoder_params=%*
start "" /wait "encoder.bat" %encoder_params%

:start_askparam
AskParam64.exe" /v600 /c"Encoder" /p"Enter Filename:" /t"my list of encoder options" /p"Select Mode:" "%~0" %%1  %%2
Ok, then it nearly works, but I get this error when my encoder (which is in another batch file as shown above) starts

"The filename, directory name, or volume label syntax is incorrect.
Not enough storage is available to process this command."

Do you know why I get this error? I put a pause just before that error occurs to echo %* to make sure the command line to the encoder batch file is correct, and it is.

Update - Ok, I had to modify the start command line to include the path -

Code: Select all

start "" /wait /D "path to encoder.bat" encoder.bat %encoder_params%
Now it works!

Update - One more problem. Now I'm getting "Terminate Batch Job" Y/N?
before AskParam restarts. Can't find how to prevent this anywhere yet!!

Update - Had to add /B switch to start command to prevent new window opening -

Code: Select all

start "" /wait /B /D "path to encoder.bat" encoder.bat %encoder_params%
Now encoding starts and new AskParam window opens at the same time. I just wait for encoding to end then fill in AskParam again. I don't know why AskParam starts at the same time. I have /wait in there but it seems to be ignored when I added /B.

Decided to replace "start" command with "call" command

Code: Select all

call ".\encoder.bat" %encoder_params%
Now I get the pause during encoding and AskParam then restarts when encoding finished. Perfect!

So why was "start" command recommended instead of "call" command?
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

I want to go directly into AskParam first if there is no %1, so here it is -
This is what was in my batch too, the only difference was initial text in AskParam prompt.
So why was "start" command recommended instead of "call" command?
You're right, call command is a better way to start batch files with waiting. I just forgot about it.

Glad to see that you got it working finally!
seb-
Senior Member
Senior Member
Posts: 276
Joined: 2011-11-15, 06:14 UTC
Location: DE\BN - only part time TC user after switching to Linux ;)

Post by *seb- »

2MVV:

it just occured to me that i used AskParam to pass a password to another application. Of course i used the /p param to mask the input field.

It took me 3 times until i realized the app did not behave correctly because i had CapsLock enabled and the password was entered incorrectly.

Did you ever consider to somehow indicate the CapsLock status in case askparam is called with /p parameter?

If it is not too much of an effort i would appreciate this for the next version :-)

Thanks!
brSeb
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

Well, I don't know if it is easy with just Windows API to show tooltip or whatever else... Maybe I'll find some way but I can't say when.
User avatar
tbeu
Power Member
Power Member
Posts: 1336
Joined: 2003-07-04, 07:52 UTC
Location: Germany
Contact:

Post by *tbeu »

Displaying a simple tooltip with WinAPI only is not a big deal.
TC plugins: Autodesk 3ds Max / Inventor / Revit Preview, FileInDir, ImageMetaData (JPG Comment/EXIF/IPTC/XMP), MATLAB MAT-file Viewer, Mover, SetFolderDate, Solid Edge Preview, Zip2Zero and more
seb-
Senior Member
Senior Member
Posts: 276
Joined: 2011-11-15, 06:14 UTC
Location: DE\BN - only part time TC user after switching to Linux ;)

Post by *seb- »

MVV wrote:Well, I don't know if it is easy with just Windows API to show tooltip or whatever else...
maybe just display some text like "CL" next to the box? It does not need to be fancy, just very basic but visible :)
MVV wrote: Maybe I'll find some way but I can't say when.
Christmas is coming soon ;-)

thx!
User avatar
crconner
Junior Member
Junior Member
Posts: 23
Joined: 2004-12-25, 22:44 UTC
Location: USA

Batch program template using AskParam for SAME batch file

Post by *crconner »

MVV wrote:AskParam can't restart itself but you can do it from batch file, e.g.:

Code: Select all

@echo off
if -%1==- goto start_askparam
rem Here you process parameters %1, %2 etc and call encoders
if -%1==-encoder1 start "" "X:\Path\To\encoder1.exe" parameters
...

:start_askparam
rem Here you start AskParam that will then call this batch back
start "" "X:\Path\To\AskParam.exe" choice parameters "%~0" %%1 %%2 %%3 %%4 ...
Just run this batch and it will start AskParam.
MVV, AskParam can be very usefull. This is an interesting trick so AskParam can supply parameters to the rest of the SAME batch file.

I took your idea, and coded up a nicely documented version into a usable batch template. This is simply a cleaned up version of your idea. It also correctly handles spaces for the parameters. I hope this helps somebody.

Code: Select all

@rem This program template shows how to use AskParam's combo box results later on in this SAME batch file.  
@rem It does this by a trick whereby it invokes itself a second time, but with the combo box as arguments.

@prompt $g$s
@echo off
@rem If this is the first run of this batch file, there will be NO arguments.
if not #%1#==##   goto second_instance_of_batch

@rem This is the first run of this batch file.  Use AskParam to get parameters, 
@rem and then run this batch file again, this time with parameters.
set this_batch_file=%~0
set Arg1=
set Arg2=

@echo Running the first instance of this batch file. Ask for the parameters.  
@rem Then invoke this same batch file again, this time with the entered parameters as arguments.
AskParam.exe /v600 /c"Running: %this_batch_file%"    ^
    /t"C:\folder num One" /p"Enter arg 1:"    ^
    /t"R:\sub\folder num Two"  /p"Enter arg 2:"    ^
    "%this_batch_file%"  "%%1"  "%%2" 
@rem AskParam phase done.  Exit this first instance of this batch file.
exit



:second_instance_of_batch
@echo Running the second instance of this batch file.
@rem the call from AskParam puts double quotes around the parameters.  We must remove them:
set Arg1=%1
set Arg1=%Arg1:~1,-1%

set Arg2=%2
set Arg2=%Arg2:~1,-1%

@echo Arg1=[%Arg1%]    Arg2=[%Arg2%]

@rem
@rem Put all the code here that you want your batch file to perform, using the entered parameters.
@rem

@echo Press any key to exit this batch file......
@pause >nul
@exit
Last edited by crconner on 2015-02-07, 05:09 UTC, edited 2 times in total.
My hero, Mr. Ghisler. License #37856 since 1999.
User avatar
crconner
Junior Member
Junior Member
Posts: 23
Joined: 2004-12-25, 22:44 UTC
Location: USA

request option

Post by *crconner »

For the purpose of using AskParam inside of the SAME batch file that calls it, the code template I just entered works fine. But, the truth is, it invokes a trick, namely calling itself a second time. And tricks often cause problems later on. There would be no need for this trick if the following option could be added to AskParam. In addition, multiple calls to AskParam can then be done inside the same batch file in different places.



Add option

/e"Environmental_Variable_name"

This environmental variable is then SET to the value entered from the combo box. This option is placed after each /p option. The rest of the batch file can then utilize the %Environmental_Variable_name%.

If environmental variables are set, the <command to execute> may or may not be specified. AskParam "falls through" to the rest of the commands in the batch file. (It actually seems to do this already.) The environmental variables are now usable in the batch file.
My hero, Mr. Ghisler. License #37856 since 1999.
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

Yes, AskParam may be called from same batch multiple times, and first parameter passed by AskParam to batch may be e.g. a counter or a label identifier to allow jumping to next batch part. BTW @ character is not necessary in every line: @echo off command turns off echoing so @ are not needed below it (that's why this command should be the first one in a batch).
Add option

/e"Environmental_Variable_name"
I think you'll like a similar thing that is realized in latest betas.


I forgot to mention that there were new betas, so:

AskParam Beta 134

+ parameter /a to set topmost mode
+ user choices are also put into enviromnent variables AskParam1, AskParam2, ...
+ parameter /e- disables environment variables' expanding in /t and /u
* smoother dialog icon
User avatar
crconner
Junior Member
Junior Member
Posts: 23
Joined: 2004-12-25, 22:44 UTC
Location: USA

Post by *crconner »

Well, it seems great minds think alike.

I went on http://forum.wincmd.ru as your link provided. Thank you. It's good that you provide the variables AskParam1, AskParam2, etc. to the child process. This does seem to work. This is a step in the right direction.

But I am asking if you could provide environment variables to the PARENT process. In fact, there does not even have to be a child process that is invoked. Like this:

Code: Select all

AskParam /c"Try Batch" /w  ^
    /tC:\ /envvar"Env_var_1"  /p"Enter variable 1 value" ^
    /tG:\ /envvar"Env_var_2"  /p"Enter variable 2 value" 

@echo Parent Process Parameters are %Env_var_1%   %Env_var_2%
I believe that adding this feature would greatly increase the applications that AskParam could be used for.
My hero, Mr. Ghisler. License #37856 since 1999.
Post Reply