PDA

View Full Version : Get environment variable path of server from local system



npatil15
23rd August 2019, 12:54
Hi Everyone,

I'm working on a local system, and my one file is stored on a server.

Let's say, On Server, we have set an environment variable (setx FILE //173.15.3.40/myUser/file.txt).
That variable is used in a file(serverFile.xml) stored in server itself.


serverFile.xml
----------------------------------------------
<property index="0" name="File Name" value="%FILE%"/>
----------------------------------------------

Now, I'm accessing this file(serverFile.xml) from a local server, and I can access it, but my local system don't know what is FILE means. I know about QByteArray qgetenv ( const char * varName ), which gives you path of that environment variable, but how I can do the same on Server from Local system using QT Programming?

I'm using QNetworkRequest, QNetworkAccessManager to communicate with the server. (REST API)

Simply how to find what is path set for FILE from our local system?

Any concept or hacks will be appreciable.

anda_skoa
26th August 2019, 10:13
Well, obviously your server side code will have to replace the variable.

This isn't something you can do locally, the implementation of the REST API needs to be able to deal with such variables.

Cheers,
_

d_stranz
26th August 2019, 17:37
Sounds like the OP's scenario is that he reads the serverFile.xml file, retrieves the property element with the "FileName" attribute, reads its "value" attribute (which contains the literal string "%FILE%"), and is then stuck because he has no way to remotely determine the value of %FILE% on the server machine.

It doesn't sound like there is any server-side program at all, it's just being accessed as a remote file system.

But if the remote file system can set the value of an environment variable to point to a specific file, then why can't that path simply be written to the XML file instead?

And as a comment, "FILE" seems like a particularly bad choice for an environment variable that forms a critical part of a processing system. "XYZ_APP_FILE" or something a bit more app-specific might be a better choice.

anda_skoa
27th August 2019, 10:08
Sounds like the OP's scenario is that he reads the serverFile.xml file, retrieves the property element with the "FileName" attribute, reads its "value" attribute (which contains the literal string "%FILE%"), and is then stuck because he has no way to remotely determine the value of %FILE% on the server machine.

Right, thus the client needs to pass on the path with the variable intact so that the server can interpret it.



It doesn't sound like there is any server-side program at all, it's just being accessed as a remote file system.

Well, the comment said server access happens through a REST API, so I assumed it would have some for of "get file" call.
This call needs to support paths with environment variable for this to work properly.

Cheers,
_

d_stranz
27th August 2019, 19:02
Well, the comment said server access happens through a REST API, so I assumed it would have some for of "get file" call.
This call needs to support paths with environment variable for this to work properly.


Ah, yes, missed that. So there must be some server-side code running, and that's where the environment variable needs to be resolved.