I've got the line gm -mogrify -level 30%,10,100% Edit.jpg in a .bat file that executes perfectly when I type it manually. However, it ends the line on the first comma of the argument when executed as a batch script.
How should I rewrite this to make it work?
Thank you.
% is a special character in batch script. Use %% instead.
Related
I am using a batch script to create and write into a .vbs file.
The file is named invisible.vbs.
This is the batch script that creates and write the .vbs script.
echo.>"C:\Users\LinFamily\Desktop\invisible.vbs"
echo CreateObject("Wscript.Shell").Run &WScript.Arguments(0)&,0,False >> invisible.vbs
The first line of code runs fine and invisible.vbs is created, but the script does not write the second line of code to invisible.vbs , instead, it tries to run it like it is a code.
I used quotation marks,
"CreateObject("Wscript.Shell").Run &WScript.Arguments(0)&,0,False" >> invisible.vbs
and the code gets written onto invisible.vbs, but the quotation marks get written onto invisible.vbs too, and that is not what I want. Invisible.vbs will not work if there is a quotation mark.
I have tried using parenthesis but that also does not work.
Is there anyway to write the code to invisble.vbs without the quotation at the end? Thanks for the help!
special characters ) and & need ^ escaping.
rem [ write all lines in one operation using parenthesis ]
> "invisible.vbs" (
echo(CreateObject("Wscript.Shell"^).Run ^&WScript.Arguments(0^)^&,0,False
)
There are ampersands in your code that do nothing, that aren't in any standard for VBScript. In short voodoo code. It is illegal VBScript code.
Ampersands and redirection are evaluated by CMD exe before other commands. So it won't write them.
So two reasons why the code don't work.
If you had tried to run that VBScript is says Line 1 Character 35 (&) Syntax Error.
Is there any utility in windows which carries out same operations done but cut command in unix.
I have input lets say A|B|C|D. Since "|" is the delimiter therefore I need to fetch all values separated by "|".
Kindly advise.
If you are trying to do this in a .cmd file you can probably find some examples by typing for /? into your command prompt. Otherwise if powershell is an option then it's as easy as using String.Split().
I was not able to add multiple change directory commands in a single batch file:
cd C:\abc\def
do something
cd C:\def\ghi
do something
It stops in the second line, and does not come back to execute the third line.
Yes you can.
I am betting that what you're doing in step 2 is calling another batch file, without using the call keyword.
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.
I have tried prefixing lines with semicolons, 'REM', etc.. but no matter what when I run my batch file I keep getting "unknown command REM whatever"
"REM test" It is not recognized, and it is windows vista. I simply get "rem" output back to my console.
That's entirely normal behavior. Batch files are simply sequences of commands that are run one after another. So every line will get output to the console as if it were typed there.
H:\>echo rem test > test.cmd
H:\>test
yields the output
H:\>rem test
as if I typed rem test directly to the console.
You can suppress this by either prefixing the line with #:
#rem test
or by including echo off in the batch file:
#echo off
rem test
If I put ":: test" and execute it I get back "Test".
Can't reproduce here.
If I put "; test" it recursively executes itself
A semicolon at the start of the line seemingly gets ignored.
If you're talking about cmd.exe batch files under Windows, you can use:
rem this method or
:: this method.
For bash and a lot of other UNIX-type shells, you use:
# this method.
I'm pretty certain you're not using cmd.exe since that would give you an error like:
'rem' is not recognized as an internal or external command,
operable program or batch file.
rather then:
Unknown command ...
If you are using a UNIX-type shell, the # character is almost certainly what you're after. If you let us know exactly the shell you're using, we can probably help out further.
you probably created an UNICODE file. These files contain 2 bytes header named BOM
which is not shown by any editor but cmd attempts to execute them and fails.
To make sure this is indeed an issue: type any other command at the very beginning
of your file and see it throws the same error - for example #echo test
To fix it, just create a new plain text file and copy content of the original file there.
then remove the original file and replace it by the newly created one.
In my case the problems are line endings. Somehow Maven or the Jenkins pipeline running on a Linux machine changed the line endings from Windows style (CR LF) to Unix style (LF). Changing them back solves the issue for me.