I need to run the below command from command prompt. How do i make it a batch file so that I do not have to type the whole command again?
c:\program files (x86)\microsoft ajax Minifier\ajaxmin.exe c:\css\reset.css c:\css\main-styles.css c:\css\lightbox.css c:\css\shortcodes.css c:\css\custom-fonts.css c:\css\custom-colors.css c:\css\admin_menu.min.css -out c:\css\mc.css -clobber
Add the >"file.bat" echo to the start of the command to create a simple batch file.
Quotes around paths and filenames with spaces and & characters are needed too.
>"file.bat" echo "c:\program files (x86)\microsoft ajax Minifier\ajaxmin.exe" c:\css\reset.css c:\css\main-styles.css c:\css\lightbox.css c:\css\shortcodes.css c:\css\custom-fonts.css c:\css\custom-colors.css c:\css\admin_menu.min.css -out c:\css\mc.css -clobber
In some cases certain characters will need escaping but for your example it will work.
Just create a new file with a .bat extension and copy these lines into it.
Then you can run it by double clicking it in Windows explorer or by typing its name in cmd prompt.
There are many ways, by the looks of it you are already running that command from a command prompt, you can write the command to a batch file like this:
echo <command> > mycommand.bat
So:
echo ajaxmin.exe c:\css\reset.css c:\css\main-styles.css c:\css\lightbox.css c:\css\shortcodes.css c:\css\custom-fonts.css c:\css\custom-colors.css c:\css\admin_menu.min.css -out c:\css\mc.css -clobber > mycommand.bat
You can also type the command into notepad or other text editor and save with a .bat extension instead of .txt.
How to create a Batch file:
Right click on your desktop or whereever you want it to
Click new text document
Rename it
Open it in notepad or whatever you want, and now you have a batch file!
Related
I'm a first-day user of IrfanView and have a question. I have a bunch of multi-page tiff files and I want to split all of them individually. So I write a batch file with the command like this:
C:\Program Files\IrfanView>i_view64.exe D:\originaldirectory\filename1.tif /extract=(D:\newdirectory,tif)
C:\Program Files\IrfanView>i_view64.exe D:\originaldirectory\filename2.tif /extract=(D:\newdirectory,tif)
...and so on...
I put the batch file on D drive, let's say in folder "batchfolder". But it can't do the job, this message shows up for each unsuccessful case (all of them were unsuccessful):
D:\batchfolder>C:\Program Files\IrfanView D:\originaldirectory\filename1.tif /extract=(D:\newdirectory,tif) 1>i_view64.exe
'C:\Program' is not recognized as an internal or external command, operable program or batch file.
I guess that has something to do with the batch file location, so I bring it to C drive. But still it can't run properly, this time a different message shows up:
C:\>C:\Program Files\IrfanView D:\originaldirectory\filename1.tif /extract=(D:\newdirectory,tif) 1>i_view64.exe
Access is denied.
This C:\>C:\ makes me think maybe the C:\ part on the batch file was redundant. So I take it out to make it look like this:
Program Files\IrfanView>i_view64.exe D:\originaldirectory\filename1.tif /extract=(D:\newdirectory,tif)
...
But it doesn't work, either with the batch file on D or C drive.
I then try to type it directly in the CMD window and it works normally, like this:
C:\Program Files\IrfanView>i_view64.exe D:\originaldirectory\filename1.tif /extract=(D:\newdirectory,tif)
Can you tell where my batch file goes wrong?
This is another question. Typing (or copy and paste) the batch file contents into the CMD works OK. But upon successful splitting, the original, multi-image file automatically opens. How can I deactivate this feature?
Note: Cross-post here: https://irfanview-forum.de/showthread.php?t=11150&p=47111#post47111. Hope it doesn't violate policy.
enclose paths/filenames with spaces into quotes to tell the interpreter, it's not two words, but one string (or even better: get used to always enclose path/filenames):
"C:\Program Files\IrfanView\i_view64.exe" "D:\originaldirectory\filename1.tif" /extract=("D:\newdirectory",tif)`
Before you build a batchfile with dozends or hundreds of nearly identical lines, use a for loop to process all .tif files in the folder:
#echo off
for %%a in ("D:\originaldirectory\*.tif") do (
"C:\Program Files\IrfanView\i_view64.exe" "%%~fa" /extract=("D:\newdirectory",tif)
)
see for /? for more information.
You need to call the executable with quotes in the batch. Also, the > in the path will not work either. Also consider using a for loop instead of creating single batch lines.
Please try this:
"C:\Program Files\IrfanView\i_view64.exe" "D:\originaldirectory\filename1.tif" /extract=("D:\newdirectory",tif)
I am having a need where I want to change the default associated program for a particular file extension from the command prompt. The file that I have is of an extension .ChangeSetInfo which is basically an xml file. I want to associate "Xml Notepad 2007" as the default program for this type of extension. For that I have written a small batch file. The content is as follows
assoc .CHANGESETINFO=
ftype CHANGESETINFO File=
assoc .CHANGESETINFO=CHANGESETINFO File
ftype CHANGESETINFO File="C:\Program Files\XML Notepad 2007\XmlNotepad.exe"
When I execute this batch file then it seems that everything is working fine as I am not getting any error message. But after that when I double click on the file with extension .ChangeSetInfo then the xmlnotepad program is launched but the file is not getting open. But the file is shown properly if I use the File Open option from the Xml Notepad window.
Can somebody please help me on this?
I am using Windows 7 Professional Service Pack 1. I am also using the administrator account on this system.
If you use assoc .doc on your system, it should return something like Word.Document.8. Typing ftype Word.Document.8 produces something like
Word.Document.12="C:\Program Files (x86)\Microsoft Office\Office15\WINWORD.EXE" /n "%1" /o /o "%u"
The "%1" indicates that it should open the file passed as the first parameter on the command line. The quotes around it make sure that any embedded spaces in that filename are not interpreted as command separators.
Therefore, the solution to your issue would be to change the ftype statement to do the same:
ftype CHANGESETINFO File="C:\Program Files\XML Notepad 2007\XmlNotepad.exe" "%1"
As a note: If it were me, I'd change both assoc and ftype to use ChangeSetInfoFile, both because it's easier to read and to remove the embedded space between "CHANGESETINFO" and "File".
In an application folder, there are n number of files. The application exe name "ClearMongoDb.exe" take some parameter like dbname.
ex: clearMongoDb.exe -db "SynchoMeshDB"
I am stuck with below :
I want to execute the exe from a batch file with same parameters
the batch file will be placed in the same application folder.
user can copy the application folder to any location
If user double clicks on the .bat file the exe should start working.
User should not be required to make any changes in .bat file
If the batch file is in the same folder as the executable, then you can do like this:
clearMongoDb.exe -db "SynchoMeshDB"
Just add this line in your batch file. Now the refference is in the same folder as the executable, no matter where the ENTIRE folder is moved (or at least the executable and batch file).
update:
As foxidrive mentioned, in order to see the output, place a PAUSE command at the end. So, your batch file should be like this:
clearMongoDb.exe -db "SynchoMeshDB"
PAUSE
If you just want to pass all the parameters given to a batch file to an EXE called from that batch file, use %*.
foo.exe %*
How do I pass command line parameters to a batch file?
You can just use a shortcut to the file and add the parameters on the path. no need for an extra batch file.
edit: unless you want to pass the batch file parameters to the .exe, as some people read this. what do you want to do? execute a .exe with the same parameters each time, or pass the .bat parameters to the .exe?
I am trying to execute a command CSRUN.exe with certain parameters from command prompt. I am able to do this using command prompt. Everytime instead of invoking this from the command prompt, i thought of writing a batch file, where in a single click will help me and also i forward this to someone who wants to execute.
Following is the one i am executing from the command prompt, which i want to have in a batch file
C:\Program Files\Windows Azure SDK\v1.1\bin>csrun.exe E:\Publish\ServiceConfiguration.csx E:\Publish\ServiceConfiguration.cscfg /launchbrowser
Can somebody suggest me how to create a batch file for invoking this command?
Just put those commands in a file
csrun.exe E:\Publish\ServiceConfiguration.csx E:\Publish\ServiceConfiguration.cscfg /launchbrowser
and name it something.bat
Just copy
csrun.exe E:\Publish\ServiceConfiguration.csx E:\Publish\ServiceConfiguration.cscfg /launchbrowser
inside an empty file and save it as a .bat..
Try using the start command and, if csrun.exe is not in your path you will need to specify an exact path for it:
start csrun.exe E:\Publish\ServiceConfiguration.csx E:\Publish\ServiceConfiguration.cscfg /launchbrowser
Save the above in a .bat file.
Also remember to put double quotes around paths with spaces in them.
Consider a directory structure containing the following files:
\1.3\Baseline\GeneratedScripts\One\FullInstall.cmd
\1.3\Baseline\GeneratedScripts\Two\FullInstall.cmd
\1.3\Baseline\GeneratedScripts\Three\FullInstall.cmd
\1.3\Patches\Patch1\GeneratedScripts\One\FullInstall.cmd
\1.3\Patches\Patch1\GeneratedScripts\Two\FullInstall.cmd
\1.3\Patches\Patch1\GeneratedScripts\Three\FullInstall.cmd
\1.3\Patches\Patch2\GeneratedScripts\One\FullInstall.cmd
\1.3\Patches\Patch2\GeneratedScripts\Two\FullInstall.cmd
\1.3\Patches\Patch2\GeneratedScripts\Three\FullInstall.cmd
\1.3\Patches\Patch3\GeneratedScripts\One\FullInstall.cmd
\1.3\Patches\Patch3\GeneratedScripts\Two\FullInstall.cmd
\1.3\Patches\Patch3\GeneratedScripts\Three\FullInstall.cmd
I would like to construct a Windows batch file InstallEnvironment.cmd which:
Takes an environment name as a parameter; then
Executes the baseline install script, and each of the patch scripts in turn.
The batch file should automatically execute any additional patches that are added later.
Essentially I need to do something along the lines of this:
for %%_ in (1.3\**\GeneratedScripts\%%1\FullInstall.cmd) do cal %%_
However I'm not sure the wildcard system is rich enough to allow this as I don't get any matches for the ** directory wildcard.
For example, calling with the parameter "Two" should execute the following scripts, in order:
\1.3\Baseline\GeneratedScripts\Two\FullInstall.cmd
\1.3\Patches\Patch1\GeneratedScripts\Two\FullInstall.cmd
\1.3\Patches\Patch2\GeneratedScripts\Two\FullInstall.cmd
\1.3\Patches\Patch3\GeneratedScripts\Two\FullInstall.cmd
This will execute all the *.cmd files in the sub folders based on the argument:
for /r 1.3\ %%X in (GeneratedScripts\%1\*.cmd) do call "%%X"
In my experience, the %1 substitution works within directory names.
This should work:
InstallEnvironment.bat:
\1.3\Baseline\GeneratedScripts\%1\FullInstall.cmd
\1.3\Patches\Patch1\GeneratedScripts\%1\FullInstall.cmd
\1.3\Patches\Patch2\GeneratedScripts\%1\FullInstall.cmd
\1.3\Patches\Patch3\GeneratedScripts\%1\FullInstall.cmd
Edit this batch file to add additional patches in order, and it works. If you need to run the same batch file on multiple directories, create another batch file:
call InstallEnvironment.bat %1
call InstallEnvironment.bat %2
If you want to run a batch file in the background, use a vbs file to run that bat file in background instead.
Here is the code:
CreateObject("Wscript.Shell").Run"""" & Wscript.Arguments(0)& """",0,False
Save this exactly as invisible.vbs (or anything) and then make another batch file which will call your batch file to run it in background.
The code for the second batch file is:
wscript.exe "invisible.vbs" "Your_Batch_File.bat"
Then run the second batch file.
Note: WSH should be enabled on your computer, and the invisible.vbs file and the second batch file should be in the same folder. If not then you can give the full path to the invisible.vbs file in the 2nd batch file's script.