15

I am following a documentation and executing some commands in Windows 10 command prompt:

export OPENAI_LOG_FORMAT='stdout,log,csv,tensorboard'
export OPENAI_LOGDIR=path/to/tensorboard/data

tensorboard --logdir=$OPENAI_LOGDIR

I have figured that export is a Unix command and the equivalent in Windows is setx. I have executed the first two commands and when I tried the third command, $OPENAI_LOGDIR is not properly detected. Can someone help with the equivalent of these in Windows?

phuclv
  • 26,555
  • 15
  • 113
  • 235
singh adi
  • 161
  • 1
  • 1
  • 3
  • if running script under cmd.exe use % to reference it: echo %OPENAI_LOG_FORMAT – TWI Nov 08 '19 at 13:18
  • **setx OPENAI_LOG_FORMAT 'stdout,log,csv,tensorboard'** makes a "user variable" **setx OPENAI_LOG_FORMAT 'stdout,log,csv,tensorboard' /m** makes a "system variable". **Note: No equal sign is used.** Variables created with `setx /m` will be available in the next cmd window you open but will not be available in the current window. Use `setx` if you want the variable to be available in the current window. – somebadhat Nov 08 '19 at 14:07
  • Hi I understood about the setx, how do I access that variable for the third command. `$OPENAI_LOGDIR` is not fetching the variable value – singh adi Nov 09 '19 at 05:20
  • 2
    TWI is unfortunately not entirely correct. In `cmd`, the syntax is `%VariableName%`. So, `%OPENAI_LOGDIR%`. Also, you might want to consider `set` instead of `setx`, depending on your use case. – Daniel B Nov 14 '19 at 20:01
  • you said that it's not working but you didn't show your code. You must show what you've tried – phuclv Feb 29 '20 at 04:12
  • just found an exact duplicate [Windows equivalent of $ in unix commands](https://superuser.com/q/1500487/241386) regarding the above commands of OPENAI_LOG_FORMAT and OPENAI_LOGDIR – phuclv Feb 29 '20 at 04:15

3 Answers3

13

you can try this:

in PowerShell

$env:OPENAI_LOGDIR="path/to/tensorboard/data"

in cmd

set OPENAI_LOGDIR=path/to/tensorboard/data
Mariem Jab
  • 131
  • 1
  • 2
11

setx is not the counterpart of Linux export in Windows. export just makes the variable available temporarily to the current shell and its children processes whereas setx stores the variable permanently to every user or system process in the future.

You didn't show all the real commands you used so based on the comments I guess you ran these

setx OPENAI_LOG_FORMAT 'stdout,log,csv,tensorboard'
setx OPENAI_LOGDIR path/to/tensorboard/data
tensorboard --logdir=$OPENAI_LOGDIR

which is absolutely wrong

First setx is supposed to be run only once, thus if you want to set the environment for the current session then you must use set instead of setx. If you do want to set the variable permanently then you'll still need to restart the shell so the changes apply, and never run the command again

Besides single quote isn't a quoting character in cmd so you'll need to remove '' and use stdout,log,csv,tensorboard, or "stdout,log,csv,tensorboard" if your program does quote removal by itself

And lastly, variables in cmd are accessed with %% instead of $ like bash, hence you must change the last line to tensorboard --logdir=%OPENAI_LOGDIR%

This is still a guess until you provide enough information in the question

phuclv
  • 26,555
  • 15
  • 113
  • 235
0

Open your computer

  1. Search for this PC icon
  2. Click on with the right button than choose properties.
  3. Click on Advanced System Settings (left part)
  4. Click on Environment Variables (right-down)
  5. Add a new system variable and save the changes

Now it will work for all users. To test open the cmd and type echo %your_variable%

for more information, see What are PATH and other environment variables, and how can I set or use them?