ShimitaichiLee Posted September 6, 2019 Posted September 6, 2019 Hi everyone, I'm new to the coding world and currently I'm struggling around getting the content of a file written into an environment variable. I'm using a Run(@Comspec) command to execute Setx. The command executes correctly i think but the problem is that the contents of the file is not written correctly into the environment variable. I opened and read the file into a string variable and then attempt to write with setx. Found this doesn't work as the environment variable didn't get updated at all. I then realized that maybe the string var itself needs to be enclosed within quotes, so i added those and it got written, but only the 1st line got in and somehow the double quotes that is supposed to be in that line is removed I've also try to remove @CR and @LF from the string var but that didn't help to get the whole content into the environment variable either. I think it is something to do with the way the contents of the file is managed... but just don't know where to look. Any advice will be greatly appreciated. #include <MsgBoxConstants.au3> #include <FileConstants.au3> Example() Func Example() Local $File = FileOpen("Machine4.txt",$FO_READ) Local $Read = FileRead($File) $Read = '"'&$Read&'"' Run (@ComSpec & " /c " & 'SETX ServiceConfig.xml.EnvName.ID '& $Read, "", @SW_HIDE) EndFunc ;==>Example Machine4.txt
Moderators JLogan3o13 Posted September 6, 2019 Moderators Posted September 6, 2019 Moved to the appropriate forum. Moderation Team "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now