Jump to content

Recommended Posts

Posted

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...