cmd: unexpected error with #pause and path>txt - windows

I am coding a batch file. Here is a sample:
if exist rootsys.txt del rootsys.txt
if %lang%==1 (
if %bit%==32 echo C:\Program Files\path\to\the dir>rootsys.txt
if %bit%==64 echo C:\Program Files(x86)\path\to\the dir>rootsys.txt
goto :waset
)
This goes on for six times (so if %lang%==2 etc... to if %lang%==6.)
So, what it does, the user puts something in, like '6', so it will do the thing for the sixth.
But, whenever i try this, it ends up with \the was unexpected at this time.
So, i tried debugging with #echo on. Seemed that it gave me the error at if exist rootsys.txt del rootsys.txt. How can that happen?!
I am 110% sure i do not mention the(actually i use this as a sample, it has another name) nowhere else in my batch file. Can anyone help me? I am really stuck here.

enclose the C:\Program Files\path\to\the dir string with "

Related

During Test Programming I have Created a File With a Faulty Filename - It Now Wont Delete

ANSWER: I have found a way of doing it. Go into the directory and type del *.*. That works. Note: typing del C:\wamp64\www\MyTest does not work. Nor does del background.jpg,..
QUESTION:
During a test programming (NodeWebkit) I have created a file with a faulty file name. The file name I have created is:
background.jpg,..
Yes, that is a comma and two periods at the end.
I cannot seem to be able to delete this file now, even in File Explorer.
Please help, how can I delete this file?
EDIT:
When I use the command line I get the following:
C:\wamp64\www\MyTest>del background.jpg,..
Could Not Find C:\wamp64\www\MyTest\background.jpg
C:\wamp64\www\MyTest\*, Are you sure (Y/N)? y
When I type y and return it does nothing.
Also note: When I do dir in the command line it includes 10/10/2017 17:51 82,792 background.jpg,..
ANSWER: I have found a way of doing it. Go into the directory and type del .. That works. Note: typing del C:\wamp64\www\MyTest does not work. Nor does del background.jpg,..

SignTool returns "The filename, directory name, or volume label...." error

I am trying to code-sign my dlls using the SignTool and Post Build Events. I use this method:
“C:\Program Files (x86)\Windows Kits\8.1\bin\x86\signtool.exe” sign /f “$(ProjectDir)archilabCertificate.pfx” /t http://timestamp.comodoca.com/authenticode /p “mypassword” "$(TargetPath)"
my certificate is located in the specified folder.
ProjectDir = D:\Google Drive\Work\GrimshawTools\GrimshawRibbon\GrimshawRibbon
TargetPath = C:\ProgramData\Autodesk\Revit\Addins\2016\GrimshawRibbon.dll
There is nothing that I can think of that could be causing this issue. I checked these paths about 100 times. I tried moving the PFX file to C drive. I tried specifying direct path to the file instead of using shorthands. I can't think of anything. Else. Ideas? How can I even debug this to find exactly what's causing the issue? I have other post builds that are working just fine.
Cheers!
Ps. I use the same certificate on my home machine and it works just fine.
The [ ” ] character is invalid! use [ " ] character.
[“]C:\Program Files (x86)\Windows Kits\8.1\bin\x86\signtool.exe[”] sign /f “$(ProjectDir)archilabCertificate.pfx” /t http://timestamp.comodoca.com/authenticode /p [“]mypassword[”] "$(TargetPath)"
Adding to the point if someone is looking for it.
I faced a similar issue, but in my case, I had the timestamp address within "<". Found a MS article which says:
"The system does not accept the keyboard combination Alt+0 through Alt+32 or the following characters: \ \ / [ ] : | < > + ; = . ? "
https://msdn.microsoft.com/en-us/library/ms832054.aspx

Windows Dos Command File Not Found (connect:direct Process)

I am using Connect:Direct process to run a DOS command to get the list of files available for collection.
If the files are available in the collection folder then the file details gets redirected to the output file (dirfile.lst). Then Connect:Direct will do a collection for those files and then delete dirfile.lst.
If there are no files in the collection folder it is expected that the dirfile.lst will be empty. And Connect:Direct will collect no files and delete dirfile.lst.
The command which I am using is
(dir "G:\Outbound\EDI\USCOLL_FTP\*" /a-d/oN ) > "F:\Sterling\Connect Direct v4.6.00\Server\program\2172047.dirfile.lst"
The problem which I am facing is when the file filter is . or *.* and if there are no files in the folder then the command throws a response "File Not Found". Connect:Direct process fails when it gets any response from the command. Interestingly I only face this issue is the file filter is . or * for any other file filter I am not getting this "File Not Found" response even though there are no files in the folder.
If I use 2> Null to fix the issue it won't display any other exceptions, hence I don't prefer to use this?
Is there a way I can get rid of File not Found message which I get when I use * and . file filters?
Any help or suggestions will be much appreciated.
It's not pretty, but this should do the trick:
>NUL 2>NUL DIR "G:\Outbound\EDI\USCOLL_FTP\*" /a-d/oN && (DIR "G:\Outbound\EDI\USCOLL_FTP\*" /a-d/oN > "F:\Sterling\Connect Direct v4.6.00\Server\program\2172047.dirfile.lst") || ECHO. > "F:\Sterling\Connect Direct v4.6.00\Server\program\2172047.dirfile.lst"
I know you didn't want to use 2>Nul but it's the best I could get. Hopefully someone will provide a better answer.

Windows batch file If/Else Start syntax?

I need to make a Windows batch file that will:
1.- Check a directory name and "If" it exists,
a.- Run a specified *.exe from a different directory.
2.- Or "Else"
a.- Rename a directory and also
b.- Rename another directory - then
c.- Run a *.exe from the created directory.
Question is: I'm stuck on the correct syntax ( I suppose) on creating this batch file. This is what I have, (maybe a nested if/Else would be better?) someone please enlighten me... Thanks.
#echo off
IF EXIST "C:\Test\Dir1" (
START "C:\Test\Dir\Test.exe"
) ELSE ( ren "C:\Test\Dir" "C:\Test\Dir1"
ren "C:\Test\Dir2" "C:\Test\Dir"
START "C:\Test\Dir\Test.exe"
)
You can't ren with a target name including a path or drive.
try
ren "C:\Test\Dir2" "Dir"
start has odd syntax - 'though it seems to not be the problem in this case. The first "quoted argument" string becomes the window title and can be routinely disregarded by the executable. Try
routinely using
start "window title that can be empty if you like" "executablename" argument list
Even if this arguably doesn't comply exactly with the documented behaviour.
(and simplifying problems to a generality can obscure the real cause, too)
Thanks dbenham and Magoo. Your responses made a world of difference on something that seems quite simple. It is now working as all the changes you both mentioned help. The final "nail in the coffin" was understanding the syntax for the START parameters. Understanding that the first parameter has double quotes and it uses that as the optional TITLE for the new window, ssoooo giving it an empty double quote ( "" ) gives it an empty title before the name of the program to fake it out. And Voila...
Thank you guys sssooo much. Final Working batch file.
#echo off
IF EXIST "C:\Test\Dir1" (
START "" "C:\Test\Dir\Test.exe"
) ELSE ( ren "C:\Test\Dir" "Dir1"
ren "C:\Test\Dir2" "Dir"
START "" "C:\Test\Dir\Test.exe"
)

Different behavior of cmd on Win7 and XP

I am trying to run following code through cmd.
"C:\Program Files\Beyond Compare 2\BC2.exe" #"C:\New Folder\Myscript.txt" "C:\New Folder\A.txt" "C:\New Folder\B.txt"
This will actually open Beyond Compare and compare two text files.
The problem is ,when i run this code on cmd[Version 6.1.7601] it runs correctly but when i run it on version 5.1.2600 , it shows a fatal error :- Could not find C:/New .
I understand the error is due to space in the name(New Folder) , but why is it running fine on Win 7 .Does two versions of cmd have some difference in the way they accept arguments ?
Content of Myscript.txt :-
file-report layout:side-by-side &
options:display-all &
output-to:%3 output-options:html-color,wrap-word %1 %2
I can't explain why it is not working, but I have some potential solutions
1) Run with the current directory at the location of the files
Since the space is in the folder name, and all files are in the same location, you can avoid the folder name by simply changing directory to that folder and using a relative path.
pushd "c:\new folder"
"C:\Program Files\Beyond Compare 2\BC2.exe" #Myscript.txt A.txt B.txt
Of course this will not work if your files are in different locations, or if the file names have spaces (assuming spaces are really the problem)
2) Use the short 8.3 names
I hate the short 8.3 names because of the many bugs associated with them. But sometimes they can be useful.
You can get the short name of a file or folder by using DIR /X. Or you could use the following in a batch script to programmatically get the short paths.
for %%A in ("C:\New Folder\Myscript.txt") do (
for %%B in ("C:\New Folder\A.txt") do (
for %%C in ("C:\New Folder\B.txt") do (
"C:\Program Files\Beyond Compare 2\BC2.exe" #"%%~fsA" "%%~fsB" "%%~fsC"
)
)
)
Of course the above will not do any good if short 8.3 names are disabled on your volume.
If i understood correctly Raymond's comment ,the parsing is done by Beyond Compare not cmd.
I tried to use
file-report layout:side-by-side &
options:display-all &
output-to:"%3" output-options:html-color,wrap-word "%1" "%2"
and it worked fine on XP but shows error on windows 7 .It seems the beyond compare behaves differently for different OS.

Resources