0

A previous batch file that we used had an accidental extra " in one of the scripts, so now anything that gets added on is not being seen.

I'm unable to find a good answer as to how to remove the extra " from the Path variable. Any advice?

Current Path:

%M2_HOME%\bin;%JAVA_HOME%\bin;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0";C:\Program Files\Puppet Labs\Puppet\bin

As you'll see, after the Powershell\v1.0, there is an extra ".

Any advice would be more than appreciated. I've been banging my head on this for quite awhile.

1
  • Trying to create a new batch file that could be run to take care of this without any one going into their system variables. Commented Apr 24, 2015 at 20:07

2 Answers 2

1

System in Control Panel - Advanced System Setings - Advanced tab - Environmental Variables.

Sign up to request clarification or add additional context in comments.

Comments

0

Assuming I have a variable PATH that I create to hold an environment variable called %PATH%, this is what I would write.

SET PATH=%PATH:"=%

DOS string substitution syntax is a colon followed by the substring to replace then an equal sign followed by the text to replace the substring with. So what the :"= does is replace all " in the %PATH% variable with nothing.

SET MYPATH=F:\cyntrx\deploy\scripts\automated_tasks\ReportIftaVehicleCode\
ECHO MYPATH
SET PATH=%MYPATH:\=%
ECHO PATH

In order to actually change the Windows %PATH% environment variable instead of just "fixing" the environment variable for the batch file itself to use, then use the setx /m command in the batch file. IMPORTANT: The change will not be shown by the ECHO command until the command prompt is closed and restarted.

System variable:

setx path "%PATH:"=%" /m

User variable:

setx path "%PATH:"=%"

6 Comments

That's very close to where I was: Set PATH=%PATH:"=% However, if you open a new CMD window and run Echo %PATH% again, it's back. It seems that that method doesn't save the edit? Does that make sense?
Right, echo PATH, not %PATH%. PATH is your modified string. (updated my answer to show)
Ah, I think I understand now. Your batch file is actually trying to update the environment variable, not "fixing" the environment variable for its own use. In that case it's the setx /m command.
Yes :) Sorry for the confusion on my part. The environment variable is what needs to get changed on all the servers that had this problem.
How would you write that? I'm getting invalid syntax saying it is not allowed more than '2' times?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.