First time poster.
I use a program called PDW. It scans pager frequencies and displays pager messages on the screen.
One of the functions is that it can run a batch or COM file when it pics up a message to a specific pager.
It also has the function to be able to pass through "optional arguments" to the batch or COM file.
.
This is what it says in the help document of the program;
Command file
The command file lets you run an external program file (with optional arguments) when
you receive a filter match and the filter has the “Enable filter command file” enabled.
This program file can be any executable file or a “.BAT” or “.COM” file.
“Browse” lets you browse for a filename, or you can just type in a filename directly.
In the “arguments” control you can enter the arguments to be passed to the command
file.
These can be anything you like or any of these special character sequences :
%1 Address
%2 Time
%3 Date
%4 Mode
%5 Type
%6 Bitrate
%7 Message
%8 Label
For example : “%1” “%2” “%3” “%7” will expand to something like :
1234567 15:21:44 01-02-10 This is a TEST message
Currently I have the following batch file set up (found on stackoverflow), which creates a popup but does not display the optional arguments...
>#echo off
echo code=Msgbox(" ALERT!", vbYesNo, "TRIGGER ALERT") > "%temp%\popupBox.vbs"
echo WScript.Quit code >> "%temp%\popupBox.vbs"
cscript /nologo "%temp%\popupBox.vbs"
if %errorlevel%==6 call :ok_tag
if %errorlevel%==7 call :cancel_tag
echo Done!
exit /b 1
:ok_tag
echo You pressed Yes!
exit /b
:cancel_tag
echo You pressed No!
exit /b
What I want to do, is have a file that not only creates a pop up on my screen, but also can receive these optional arguments from the program (Specifically %1 Address, %2 Time, %3 Date, and %7 Message).
So can anyone help me with a code that will do what I want?
This change should give you extra info in the popup
echo code=Msgbox(" %~1 - %~2 - %~3 - %~7 ", vbYesNo, "TRIGGER ALERT") > "%temp%\popupBox.vbs"
Related
I have one folder which contain another subfolder and that subfolder contains different extensions file.
Now I want using batch script how to extract name and time of that file in a subfolder.
I tried but failed to retrieve time of that file which is located in subfolders.
I want only this code in the batch script only.
using substitution of variable reference for /?, echo can be changed by any other command or call
command-line
for %f in (filepath\pattern) do echo "%f : %~tf"
in a script the percent sign must be double
for %%f in (filepath\pattern) do echo "%%f : %%~tf"
EDIT after comment
here an example of how to use labels to simulate function and to avoid expansion tricks, note that labels are not exactly functions they are executed in normal flow, that's why there's goto :main to skip :process and goto :eof to return.
#echo off
goto :main
:process
echo file name is: %~1 and time is %~2
goto :eof
:main
for %%x in (AppData\Local\*.*) do call :process "%%x" "%%~tx"
but with batch script command set is very limited, also should be noted that date and time output can't be formatted and are dependent of system language settings.
If powershell can be used, it's worth taking the time to learn.
Different file time properties :
$file.CreationTime
$file.CreationTimeUtc
$file.LastAccessTime
$file.LastAccessTimeUtc
$file.LastWriteTime
$file.LastWriteTimeUtc
I made a script named Start_in_call.bat
#echo off
title Start in Call
echo Start Script
echo Parameters : [%0 %1 %2]
call :label1
echo End of Script
pause
exit
:label1
echo Start of Label1
echo Parameters : [%0 %1 %2]
pause
Start_in_call.bat rem qwe
echo End of Label1
goto :EOF
I expect the script to open itself with rem qwe as the parameter
I ran the file and this is the output:
Start Script
Parameters : ["S:\alot\of\folders\Start_in_call.bat"]
Start of Label1
Parameters : [:label1 ]
Press any key to continue . . .
Start of Label1
Parameters : [Start_in_call.bat rem qwe]
Press any key to continue . . .
Start of Label1
Parameters : [Start_in_call.bat rem qwe]
Press any key to continue . . .
I noticed that the script do some kind of goto label1 instead of opening itself
Anyone know how did this happen?
When you use a call command, a new "batch context" is created, the code in the batch file readed and if it is determined that the context has been created by a call :label a implicit goto :label is executed.
Now, from inside the subroutine you directly invoke a batch file (doesn't matter if the same or other batch file) but without using the call command. This creates a batch context that replaces the current context but does not clear the previous call :label situation. This leads to a new implicit goto :label
This is used to implement a "library of functions" (you can see a working sample here)
Change your Start_in_call.bat to call Start_in_call.bat.
i dont get it. I would like to pass multiple parameters to a batch file, that has the following description:
When passing parameters instead the first parameter (%1) should be PARAM and the
other parameters are shown in the list.
%epin% or %1 contains the file with full path and no extensions for input files
%epout% or %2 contains the file with full path and no extensions for output files
%epinext% or %3 contains the extension of the file selected from the EP-Launch
program. Could be imf or idf -- having this parameter ensures that the correct user
selected file will be used in the run.
%epwthr% or %4 contains the file with full path and extension for the weather file
%eptype% or %5 contains either "EP" or "NONE" to indicate if a weather file is used
%pausing% or %6 contains Y if pause should occur between major portions of
batch file
%maxcol% or %7 contains "250" if limited to 250 columns otherwise contains
"nolimit" if unlimited (used when calling readVarsESO)
%convESO% or %8 contains Y if convertESOMTR program should be called
%procCSV% or %9 contains Y if csvProc program should be called
%cntActv% or %10 contains the count of other simulations active or about to be
active
%multithrd% or %11 contains N if multithreading should be disabled
All i want is to pass parameters %1, %2, %3, %4 and %5... the rest should not be set...
Can somebody please tell me how this works? I searched the web and tried for hours but i won`t get this.
Thanks and greets!
It looks to me like the author of this batch file allows you to use it in 2 different ways,
Option 1
Just pass the parameters on the command line,
file.bat Param1 Param2 Param3 .....
Option 2
set the variables listed and then call the batch file with the single parameter that is exactly PARAM.
SET epin=Param1
SET epout=Param2
...
file.bat PARAM
what is the problem with ?:
set "epin=%~dpfn1"
set "epout=%~dpfn2"
set "epinext=%~3"
if /I not .%epinext% equ .imf (
if /I not .%epinext% equ .idf (
echo wrong extension
exit /b 1
)
)
set "epwthr=%%~dpfnx4"
set "eptype=%%~5"
use a short batchfile (in fact it is very short: one line) (you could name it "DoFile.bat")
#file.bat %1 %2 %3 %4 %5 Y "250" Y Y 3 N
It takes 5 parameters and starts the wanted batch with the full amount of 11 parameters.
It might be neccessary to adapt it a little bit to the needs of file.bat
(no errorhandling included)
I'm writing a script that function as a shortcut, lets i wanna send the input to My Pictures
#echo off
echo drop input
pause
move "%1" "C:\Users\%username%\Pictures"
pause
The problem seems to be that the %1 / input needs to be described in some way.
cause when i drop a image it says
The system cannot find the file specified.
#echo off
rem Prepare environment
setlocal enableextensions disabledelayedexpansion
:loopParameters
rem Variable to hold file name
set "file="
rem If a file has been dropped on batch file, retrieve if from parameters
rem If no file dropped, ask for one
if "%~1"=="" (
set /p "file=Drop file here:"
) else (
set "file=%~1"
)
rem Check if there is something to do. If not, the process has ended
if not defined file goto endProcess
if not exist "%file%" goto endProcess
rem Do the work
echo move "%file%" "C:\Users\%username%\Pictures"
rem Determine if there is something more to process
if not "%~1"=="" if not "%~2"=="" ( shift & goto :loopParameters )
:endProcess
rem Wait to see output of commands
echo.
pause
rem Clean and exit
endlocal
exit /b
It will process files dropped into the batch file (without first starting batch file). If batch file is started without dropping any file on it , it will ask for one file to process.
If files are dropped into batch file, explorer generates the list of files to be processed as separate arguments to batch file. So first file will be in %1, second in %2, ... In this code, the file to be processed is retrieved from %1. Once the first file is processed, if there are more files to process, shift command is used to "shift" the argument list, so the content of %2 will be in %1, %3 will be in %2, ... That way, the next file to process will be again in %1 in each iteration.
BUT there is a limit of 8191 characters in the length of a command line. As explorer passes the full list of selected files in the same command line, if there is a lot of files selected, the final part of the list will not be handled.
You need the tilda in the command as shown below, as dropping quoted iems on it will fail if it doesn't have the tilda.
move "%~1" "C:\Users\%username%\Pictures"
I've made a Program that Launches other programs, but here is the problem.
You need to specify the path of the file in the code which means that the end-user needs to get into the code to specify the file which is not really the ideal situation.
I have solution in mind,when you launch the program a dialog box comes up and asks you to give it the file path so it can run the specified program. How would I go about doing something like this?
You can also do the following
#echo off
set foo=%1
echo %foo%
%1 refers to the 1st parameter that you have passed it to the program. This first parameter will then be set to the variable %foo%. Here is the example:
C:\>test.bat "C:\passwd"
C:\passwd
Hope this helps :)
Update
You can make your program to execute another program by doing the following:
#echo off
REM `%~f1` will helps to expand `%1` to a fully qualitified path name
set "executable=%~f1"
REM checks if the first parameter exist. If it did not exist, a usage text will be displayed and the program will exit
if "%executable%"=="" (
echo Usage: %0 path\to\executable
goto :EOF
) else (
call :program
goto :EOF
)
:program
echo %executable% is starting...
start "" "%executable%"
goto :EOF
You can reads user input. e.g. edit the following snippet according to you need
ECHO User will have to enter the input file path.
set /p variable=Enter input files path please:
The user can type as many letters as they want, and it will go into the delBuild variable.