Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I execute a DOS SET command from C# and have the variable persist after the exe closes?

I have a C# console executable started within a DOS command process.

I need to be able to execute DOS commands from the C# executable (specifically I need to be able to SET variables) and have the variables persist such that the rest of the DOS process can reference them.

ie:

Start DOS process -> C# executes a SET command to set UserVariable -> DOS process can ECHO %UserVariable%

Due to performance reasons I cannot write the set command to a dos script. In fact, I cannot have any file I/O at all.

Can anyone help?

like image 515
Mohammed Avatar asked Feb 21 '23 04:02

Mohammed


1 Answers

SETX persists the environment variables. Check this: http://technet.microsoft.com/es-es/library/cc755104(v=ws.10).aspx

like image 107
Ignacio Soler Garcia Avatar answered Apr 29 '23 00:04

Ignacio Soler Garcia