Batch file written in notedpad with '>' shows '1>' in dos windows. - windows

I am trying to log an output from MSDeploy command line script to a log file.
:: SYNC FILES--
"C:\Program Files\IIS\Microsoft Web Deploy V2\msdeploy.exe" -Verb:sync ^
-Source:AppHostConfig=Website1,ComputerName=Server1 ^
-Dest:AppHostConfig=Website1,ComputerName=Server2 ^
-Skip:SkipAction='Update',objectName=filePath,absolutePath=.*web.config$ ^
-Skip:SkipAction='Update',ObjectName=contentPath,absolutePath=c:\\inetpub\\apppools ^
-Skip:objectName=Binding ^
-EnableRule=DoNotDeleteRule > msdeploy.log
TIMEOUT /T 100
"> msdeploy.log" shows up as "1> msdeploy.log" and becomes unable to log anything.
Any help will be appreciated ?

The redirection with > is the short form of 1>, to redirect stream1.
This is not your problem.
But it could be a directory problem, so the file is created but not in the expected one.
This happens when the working directory is not the same as the directory where the batch resides.

Related

Windows CMD Line - Syntax Error- Parameter format not correct when trying to run command "del ..\C\D"

I have 4 folders, with A being the parent, B and C being the child of A, and D being the child of C.
A -> B
A -> C -> D
In folder B I want to generate a build via NPM and then to move the new folder over to D after deleting the previous version.
So to do this I'm trying to run the following script in the command line:
react-scripts build && rd /s/q ../C/D && move build ../C/D
Upon running this command however, I receive the following error:
Parameter format not correct - "C".
What is causing this error in particular and what would be the proper syntax to run this command?
Windows cmd prompt often requires paths to be in double quotes.
C:\Users\Me>mkdir c/d
The syntax of the command is incorrect.
C:\Users\Me>mkdir "c/d"
Windows powershell will accept the paths without quotes.
PS C:\Users\Gordon> mkdir c/d
Directory: C:\Users\Me\c
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 7/20/2022 11:51 AM d
In your example, just swap / (forward slash) with \ (backward slash) and you would probably be good to go...
react-scripts build && rd \s\q ..\C\D && move build ..\C\D
If your folder or file has empty spaces in the name you'd want to surround it with quotes.

Using `^` to escape end-of-line character in a Windows Batch file doesn't work on certain lines? [duplicate]

This question already has answers here:
Why CMD escape character does magic instead of escaping new line
(2 answers)
Closed 2 years ago.
I have a batch file that I've thrown together in order to automate the launching of a program and several associated programs in a single click. The part relevant to the question:
echo Starting FireFox with Elite Tabset...
cd "C:\Program Files\Mozilla Firefox\"
start firefox.exe ^
https://inara.cz/cmdr/276665/ https://coriolis.io/ ^
https://www.edsm.net/ ^
http://www.elitedangeroustrading.com/trade-assistant.aspx ^
https://www.edtutorials.com/ ^
"file:///C:/Program Files (x86)/VoiceAttack/Sounds/HCS Tools/Links and docs/Control packs/Singularity (Elite)/Singularity reference guide.pdf" "file:///C:/Program Files (x86)/VoiceAttack/Sounds/HCS Tools/Links and docs/Companion packs/Ships assistant Ad-Astra/Ad-Astra reference guide.pdf" "file:///C:/Program Files (x86)/VoiceAttack/Sounds/HCS Tools/.Voice command lists/Elite Dangerous Voice Commands/Singularity ship commands.html" "file:///C:/Users/Guillermo/Downloads/ebonym-t16000mfcs.jpg"
echo Starting EDDiscovery...
As you can see, I've used the ^ character to break the start firefox command into multiple lines for readability's sake. This file, as shown, works. However, note the 2nd-to-last line, which starts with "file:///". There are multiple parameters on that line. What I tried to do is:
echo Starting FireFox with Elite Tabset...
cd "C:\Program Files\Mozilla Firefox\"
start firefox.exe ^
https://inara.cz/cmdr/276665/ https://coriolis.io/ ^
https://www.edsm.net/ ^
http://www.elitedangeroustrading.com/trade-assistant.aspx ^
https://www.edtutorials.com/ ^
"file:///C:/Program Files (x86)/VoiceAttack/Sounds/HCS Tools/Links and docs/Control packs/Singularity (Elite)/Singularity reference guide.pdf" ^
"file:///C:/Program Files (x86)/VoiceAttack/Sounds/HCS Tools/Links and docs/Companion packs/Ships assistant Ad-Astra/Ad-Astra reference guide.pdf" ^
"file:///C:/Program Files (x86)/VoiceAttack/Sounds/HCS Tools/.Voice command lists/Elite Dangerous Voice Commands/Singularity ship commands.html" ^
"file:///C:/Users/Guillermo/Downloads/ebonym-t16000mfcs.jpg"
echo Starting EDDiscovery...
When I do that, I get the below output:
C:\Program Files (x86)\VoiceAttack>echo Starting FireFox with Elite Tabset...
Starting FireFox with Elite Tabset...
C:\Program Files (x86)\VoiceAttack>cd "C:\Program Files\Mozilla Firefox\"
C:\Program Files\Mozilla Firefox>start firefox.exe https://inara.cz/cmdr/276665/ >https://coriolis.io/ https://www.edsm.net/ http://www.elitedangeroustrading.com/trade-assistant.aspx https://www.edtutorials.com/ "file:///C:/Program Files (x86)/VoiceAttack/Sounds/HCS Tools/Links and docs/Control packs/Singularity (Elite)/Singularity reference guide.pdf" ^
C:\Program Files\Mozilla Firefox>"file:///C:/Program Files (x86)/VoiceAttack/Sounds/HCS Tools/Links and docs/Companion packs/Ships assistant Ad-Astra/Ad-Astra reference guide.pdf" "file:///C:/Program Files (x86)/VoiceAttack/Sounds/HCS Tools/.Voice command lists/Elite Dangerous Voice Commands/Singularity ship commands.html" ^
The filename, directory name, or volume label syntax is incorrect.
C:\Program Files\Mozilla Firefox>"file:///C:/Users/Guillermo/Downloads/ebonym-t16000mfcs.jpg"
The filename, directory name, or volume label syntax is incorrect.
C:\Program Files\Mozilla Firefox>echo Starting EDDiscovery...
Starting EDDiscovery...
I don't understand why I am able to separate the first 4 arguments out, but not the ones that start with "file://. Is there some subtle facet of the ^ I am missing or mis-using? Is there a different technique for this kind of cleanup? I acknowledge that it is purely a readability concern, but it is vexing to not be able to explain this behavior.
The problem are lines beginning with a double quote, because a caret at a line end escapes the line end AND the first character of the next line.
That results in escaping the first quote and the "closing" quote at the end of line is interpreted as an "opening" quote, instead.
This can be solved by simply prefix each line with a space.
start firefox.exe ^
https://www.edsm.net/ ^
https://www.edtutorials.com/ ^
"file:///C:/Program Files/guide.pdf" ^
"file:///C:/Program Files/blapdf" ^
...
There exists a second, more obscure solution for the problem, adding redirects in front of the carets.
With this approach the first character of the next line works as expected (will not be escaped)
start firefox.exe ^
https://www.edsm.net/ <nul ^
https://www.edtutorials.com/ <nul ^
"file:///C:/Program Files/guide.pdf" <nul ^
"file:///C:/Program Files/blapdf" <nul ^
...
More at SO:Long commands split over multiple lines..

"Missing parameter for command 'get'" when downloading files within date range using WinSCP

I am using below command to download files from FTP but I am getting error
"get -filemask="*>=2018-12-01" -preservetime -resume -speed=5000 /ECC/PITR/WAL_ARCHIVE E:\ECC\PITR\WAL_ARCHIVE\" ^
"exit"
Error:
> 2020-12-17 12:46:50.392 Script: get -filemask=*
< 2020-12-17 12:46:50.392 Script: Missing parameter for command 'get'.
You have the quotes wrong.
Either double the inner quotes:
"get -filemask=""*>=2018-12-01"" -preservetime -resume -speed=5000 /ECC/PITR/WAL_ARCHIVE E:\ECC\PITR\WAL_ARCHIVE\" ^
Or as the quotes around the file mask are redundant, as there's no space in the mask, you can remove them altogether:
"get -filemask=*>=2018-12-01 -preservetime -resume -speed=5000 /ECC/PITR/WAL_ARCHIVE E:\ECC\PITR\WAL_ARCHIVE\" ^
See also Why are some WinSCP scripting commands specified in a batch file not executed/failing?
If you want to avoid downloading folders, that do not contain any relevant files, see Download files newer than X days from SFTP server with WinSCP, skipping folders that do not contain any matching files.
Is the connection open before calling get?
https://winscp.net/forum/viewtopic.php?t=11089
..."Script: Missing parameter for command 'get'."...
martin:
winscp.exe /console /command "option batch abort" "open root:password#192.168.1.11/private/var/root/folder1/" "get file1 c:\Users\me\Desktop\folder2"

Change maven settings.xml location and pass -s automatically

Intro
I moved my settings.xml file to a secured network share which only I can access.
The next step is to encrypt various credentials inside the file as well.
Unfortunately, now when I run mvn I need to specify the location every time, e.g.:
mvn -s Z:\CONFIG\settings.xml
Solution Try - Aliases
I tried making an alis in CMDER but I always get a goal not specfied error.
E.g. in user_aliases.cmd I add the following tries:
mvn1=echo "Using custom cmder alias (cmder user_aliases.cmd) : mvn -s Z:\CONFIG\settings.xml " & mvn -s Z:\CONFIG\settings.xml
mvn2=mvn -s Z:\CONFIG\settings.xml
They both fail with an error about goals not being passed.
So this is an issue with the arguements not being passed.
Anyone have a solution for hardcoding this location permanently???
Update
My current solution has been to edit the mvn.cmd file itself.
I added something like the following, and it works.....
though it breaks mvn for anyone else wanting to use it:
echo "Modified mvn.cmd to add custom path mvn -s Z:\CONFIG\settings.xml "
"%JAVACMD%" ^
%JVM_CONFIG_MAVEN_PROPS% ^
%MAVEN_OPTS% ^
%MAVEN_DEBUG_OPTS% ^
-classpath %CLASSWORLDS_JAR% ^
"-Dclassworlds.conf=%MAVEN_HOME%\bin\m2.conf" ^
"-Dmaven.home=%MAVEN_HOME%" ^
"-Dlibrary.jansi.path=%MAVEN_HOME%\lib\jansi-native" ^
"-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^
%CLASSWORLDS_LAUNCHER% -s Z:\CONFIG\settings.xml %MAVEN_CMD_LINE_ARGS%
if ERRORLEVEL 1 goto error
goto end
I could possibly make a copy of maven to my Z drive (secured) and call that to avoid all of this.
I tried two solutions which both worked:
Move maven to folder with permissions
One solution was to move maven directly to a protected isolated folder such a shared network folder (with appropriate permissions) or user folder.
Edit the mvn cmd file
I edited the mvn.cmd file itself.
I added something like the following, and it works.....
WARNING: it breaks mvn for anyone else wanting to use it. So use only if this is not a consideration.
echo "Modified mvn.cmd to add custom path mvn -s Z:\CONFIG\settings.xml "
"%JAVACMD%" ^
%JVM_CONFIG_MAVEN_PROPS% ^
%MAVEN_OPTS% ^
%MAVEN_DEBUG_OPTS% ^
-classpath %CLASSWORLDS_JAR% ^
"-Dclassworlds.conf=%MAVEN_HOME%\bin\m2.conf" ^
"-Dmaven.home=%MAVEN_HOME%" ^
"-Dlibrary.jansi.path=%MAVEN_HOME%\lib\jansi-native" ^
"-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^
%CLASSWORLDS_LAUNCHER% -s Z:\CONFIG\settings.xml %MAVEN_CMD_LINE_ARGS%
if ERRORLEVEL 1 goto error
goto end

Change directory and executing external command in cmd - ERLANG

I am working on Erlang script that need to execute some command in cmd. I was trying to solve problem on this way, but I get nothing.
start() ->
comparing(0000).
comparing(Num) ->
file:set_cwd("F:\Documents\UPI\dump_rabbitmq\rabbitmq-dump-queue-v0.3-windows-amd64"),
DirOut = os:cmd("dir"),
io:format("DirOut=~p~n", [DirOut]),
os:cmd('rabbitmq-dump-queue -uri="amqp://username:password#localhost:5672/" -queue=try -full -max-messages=5 -output-dir=E:\Programs\Erlang\erl8.3\usr'),
NumMes = Num,
io:format("NumMes=~p~n", [NumMes]),
NameF = "msg-000",
io:format("NameF=~p~n", [NameF]),
FileName = concat(NameF, lists:flatten(io_lib:format("~p", [NumMes]))),
io:format("FileName=~p~n", [FileName]),
File = filelib:is_regular(FileName),
io:format("File=~p~n", [File]),
...
This is just a part of code where I have a problem. In line file:set_cwd("F:\Documents\UPI\dump_rabbitmq\rabbitmq-dump-queue-v0.3-windows-amd64") I want to change directory.
In this two lines I check if directory is changed:
DirOut = os:cmd("dir"),
io:format("DirOut=~p~n", [DirOut])
And in line os:cmd('rabbitmq-dump-queue -uri="amqp://username:password#localhost:5672/" -queue=try -full -max-messages=5 -output-dir=E:\Programs\Erlang\erl8.3\usr') I want to execute command in cmd for dump messages from RabbitMQ server. I was trying to change directory with os:cmd("cd F:\Documents\UPI\dump_rabbitmq\rabbitmq-dump-queue-v0.3-windows-amd64"), but nothing happends. Any suggestion how to solve this problem?
EDIT
Problem is solved. It's neccesary to have two slashes in this line: file:set_cwd("F:\\Documents\\UPI\\dump_rabbitmq\\rabbitmq-dump-queue-v0.3-windows-amd64") Dogbert solved the problem in comments.
There are two problems in the code:
You cannot change the working directory with os:cmd("cd ..."), you need to call file:set_cwd/1. os:cmd("cd ...") will only change the directory for the execution of that command, the change will not persist for future calls to os:cmd/1.
You need to escape the slashes, otherwise they're interpreted as escape sequence when it's a valid escape sequence, otherwise they're ignored.
1> io:format("~s~n~s~n", ["C:\abc\nop", "C:\\abc\\nop"]).
C:abc
op
C:\abc\nop
So, changing this:
os:cmd("cd F:\Documents\UPI\dump_rabbitmq\rabbitmq-dump-queue-v0.3-windows-amd64"),
to:
file:set_cwd("F:\\Documents\\UPI\\dump_rabbitmq\\rabbitmq-dump-queue-v0.3-windows-amd64"),
should fix your problem.

Resources