How to run 2 bat file in same server program?

Actually i want to run 2 bat scripts , first script will set a system variable[set NEWPATH=“E:/Some”] and second script will show the path of that variable(echo %NEWPATH%). this is not working with the same server at first time , when i restart server that will show the path otherwise it’ll show nothing. so can anyone help me on that?

Thanks in advance.

I am not sure if I understand all of the scenario. Would you mind sharing the relevant code snippets?

At a first glance it would seem your server spawns each script in a separate sub-shell instance. In this case, the second sub-shell would not see the variable that was set in the first sub-shell instance only. But this does not explain why the value can be read after restarting the server.

Another possible explanation is that your server executes the two commands asynchronously; that is, the call to the shell returns immediately although the shell is still busy with executing the set command. So when the server then runs the echo command, the set command has not finished yet and echo returns an empty value. To find out if this is the case, put a Sleep() call between the first and the second command execution.

you can easily manage environment variables from golang (see os package). why do you use .bat files for this?

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.