Export command on windows

The `export` command in CMD is used to set environment variables, allowing you to define or modify variables that can be accessed by child processes.

Here’s a simple example of how to use it:

set MY_VARIABLE=HelloWorld
echo %MY_VARIABLE%

Understanding the Export Functionality in CMD

Exporting in the context of Command Prompt (CMD) refers to the ability to capture the output of commands and store it in files for future reference or analysis. This functionality is particularly helpful in various scenarios, such as generating reports, logging system settings, or backing up important configuration values. Understanding how to effectively utilize export commands in CMD can significantly enhance your productivity and streamline your workflows.

Basic Exporting Techniques

Exporting Command Output

One of the simplest ways to export data in CMD is by capturing the output of a command and redirecting it to a file. The standard operator for this in CMD is the `>` symbol, which directs the output of a command to a specified file.

For example, if you want to list the contents of a directory and save that list to a text file, you can use:

dir > output.txt

In this case, the `dir` command will execute, and instead of displaying the contents directly on the screen, it will be written to `output.txt`. If the file does not exist, it will be created; if it does, its contents will be overwritten.

Using the Append Operator

In some instances, you may want to append data to an existing file instead of overwriting it. This is where the `>>` operator comes in handy.

Consider the following example:

echo This will be appended >> output.txt

This command adds the text «This will be appended» to the end of the `output.txt` file without erasing its previous contents. Using the append operator is particularly useful for logging data over time.

Advanced Exporting Techniques

Exporting with Additional Formatting

When dealing with specific data, you may want to filter the output before exporting. The `findstr` command is a powerful tool that allows you to search for specific strings in command outputs.

For instance, if you’re interested in active listening ports, you can run:

netstat -an | findstr LISTENING > listening_ports.txt

In this example, `netstat -an` generates a list of all active network connections, and `findstr LISTENING` filters them to show only those in a listening state. The final output is redirected into `listening_ports.txt`.

Exporting Environment Variables

Another common practice is exporting environment variables. This can be particularly useful for debugging or documentation purposes. To export all environment variables to a text file, you can use:

set > env_variables.txt

This captures the current state of all environment variables and saves it in `env_variables.txt`, allowing you to review system settings as needed.

Exporting Registry Settings

Exporting specific registry keys can also be performed directly from CMD, which is handy for backups or migration purposes. For example, to export registry settings for an application, you can use:

reg export HKCU\Software\MyApp registry_backup.reg

This command saves the specified registry key from the current user hive into a file called `registry_backup.reg`. This is particularly useful before making significant changes to your system.

Exporting Data into Different Formats

Working with CSV Format

CSV (Comma-Separated Values) is a widely used format for spreadsheets and databases, making it a preferred choice for many types of data exports. You can create CSV files directly from CMD using a `for` loop. For example:

for /f "tokens=*" %i in ('command') do echo %i >> output.csv

This command executes a specified command within the single quotes and captures its output. Each line of the output is then appended to `output.csv`, resulting in a CSV file that can be opened in applications like Excel.

Tips for Effective Exporting

Choosing the Right File Type

Selecting an appropriate file type for export is crucial for managing your data effectively. While `.txt` files are suitable for plain text outputs, `.csv` files are ideal for structured data, especially when dealing with tables or lists. Register files (with a `.reg` extension) are essential for exporting Windows registry keys, particularly for system configuration backups or migrations.

Handling Large Files

When exporting substantial amounts of data, you may encounter performance issues or difficulties in navigating the output files. To manage this, consider using commands like `more` to paginate the output or refine your commands to limit the volume of data being exported. For example, using filters can significantly reduce the amount of unnecessary data included.

Troubleshooting Common Export Issues

Exporting via CMD can sometimes lead to errors or unexpected outputs. Below are common issues and solutions to help troubleshoot:

  • Incorrect Permissions: Ensure CMD is running with appropriate permissions, especially when exporting sensitive data such as registry settings.
  • File Overwrite Warnings: Be cautious of overwriting existing files. Use the append operator (`>>`) when necessary to prevent data loss.
  • Missing Output Files: If you cannot find the output file, double-check the path. If no path is specified, the file will save in the current working directory.

Conclusion

Mastering the art of exporting data using CMD opens up a world of possibilities for automation and data management. Whether you’re capturing command outputs, filtering through system settings, or managing environment variables, these techniques can significantly enhance your efficiency and productivity. Practice using the various export commands to explore their full potential.

Additional Resources

For more advanced tutorials and community discussions on CMD, consider engaging with forums or enrolling in specialized courses. Additionally, exploring the official Microsoft documentation can provide in-depth knowledge about CMD’s capabilities, ensuring you stay up-to-date with the latest command utilities.

As a full-stack developer, you likely utilize environment variables extensively in your Linux/Unix environments for configuring infrastructure, tools, and application code.

However, when transitioning to Windows, the absence of the handy export command presents syntax challenges.

In this comprehensive 3100+ word guide, I‘ll demonstrate the Windows Command Prompt equivalents for setting persistent and temporary environment variables coming from a Linux background.

We‘ll cover:

  • Linux export command overview
  • Windows setx and set equivalents
  • Side-by-side syntax comparison
  • Variable scope and precedence
  • Real-world use case examples
  • Common developer transition issues

Let‘s get started!

Overview of Linux export Command

For developers on Linux or Unix-like systems, environment variables are set using the built-in export command:

export MY_VAR="some value"

This makes MY_VAR available to forked subprocesses and bash child processes. The variable remains set in the current shell until explicitly unset or the shell session expires.

Additionally, export allows you to append to system or existing variables like PATH:

export PATH="$PATH:/my/custom/path" 

Overall, export is very flexible and ideal for configuring infrastructure and applications on Linux/Unix through environment variables.

Windows Command Prompt Equivalents

When transitioning your development environment to Windows, you‘ll need to replace export with two distinct commands:

  • setx – Permanently sets user-level environment variables
  • set – Temporarily sets variables for current shell session

The following sections explore the syntax and usage of each.

setx – Setting Persistent Environment Variables

The setx command is the closest direct equivalent to Linux export for creating user-specific environment variables on Windows.

setx Syntax

The setx syntax is structured as:

setx VAR "VALUE" /M

Where:

  • VAR – Variable name
  • VALUE – Assigned variable value
  • /M – Makes variable available system-wide (optional)

For example:

setx MY_PATH "c:\MyFolder"

This creates an environment variable named MY_PATH with value c:\MyFolder, available every time the user opens Command Prompt.

The /M switch optionally makes it available machine-wide to all users.

Appending Variables

You can also append or modify existing variables like PATH:

setx PATH "%PATH%;C:\new\path"

This is similar to Linux export syntax.

Persistence

Any variables set with setx permanently remain set for that user unless explicitly cleared using:

setx MY_VAR /D

This has the same persistence as using export in bash.

set – Temporary Session Variables

For temporary, session-specific variables, use the set command instead of setx on Windows.

set Syntax

The set syntax looks like:

set VAR=VALUE

For example:

set MY_VAR=temp

Unlike setx, this variable is only available for the lifetime of the current shell session. When the shell/process exits, it is cleared.

Scopes

set exclusively works on a per-session basis. There is no concept of persisting variables outside the current shell like setx and export provide.

Clearing Variables

You can clear a temporary set variable by simply calling:

set MY_VAR=

With no value assigned, it is removed entirely for that session.

Side-By-Side Syntax Comparison

Here is a helpful table contrasting export syntax vs setx and set in Windows:

Command Linux/Unix Syntax Windows Syntax
Permanent export MYVAR=»value» setx MYVAR «value»
Temporary export MYVAR=»temp» set MYVAR=temp
Append export PATH=»$PATH:/my/path» setx PATH «%PATH%;C:\my\path»
Clear unset MYVAR setx MYVAR /D (or close session for set)

While structurally similar overall, the key differences come down to:

  • No export keyword
  • Use of semi-colons for path separators
  • Double quotes for long values

Once you adapt to these subtle syntax variances, the functionality remains fairly equivalent between operating systems.

Scope, Precedence and Visibility

In terms of scope, precedence, and visibility, environment variables work similarly between Linux and Windows with a couple caveats.

By default, user-level variables defined with setx:

  • Are available only to current user
  • Are accessible across sessions and new processes
  • Can be overridden by machine/system-level variables

Machine-level variables configured by administrators generally take precedence.

Meanwhile, set variables:

  • Are accessible only to current shell and its children
  • Override user and machine-level values
  • Are cleared completely after session exits

So the order of precedence is:

  1. set session variables
  2. User setx variables
  3. Machine system variables

Similar to how Linux handles various export scopes and sourcing files, overriding variables.

One key Windows difference is visibility:

  • By default users see only their own environment variables
  • Admins have access to see all system and user variables

Linux environments tend to allow regular users more visibility.

Practical Usage Examples

With the basics covered, let‘s now explore some real-world examples developers can implement for tooling and infrastructure configuration.

Configuring Local Development Environment

Common case – you need to set up PATH, tool paths, configs etc for your day-to-day coding:

// Append common tool locations 
setx path "%path%;%ProgramFiles%\Common Files\Oracle\Java\javapath"

// Set variable to force Python version  
setx pythonpath "C:\Users\name\miniconda3"

// Set config default for my tool 
setx my_tool_cfg "%AppData%\MyTool\config.json"

This mimics what you may be used to having in your ~/.bash_profile on Linux.

Build System Configuration

For build pipelines, you may need to customize environment variables before triggering application/package builds:

// Set temporary build flags
set customize_build=true

// Override config to specify artifact storage 
set myapp_artifact_path=\\server\builds  

// Launch the build process
build.bat

By using set, any variable customizations stay contained to the build rather than leaking out to rest of system.

Infrastructure Orchestration

Infrastructure-as-Code pipelines often need to configure runtime properties for the environment:

// Get base AMI image ID from parameter store
setx base_ami=%ssm_val%  

// Set subnet based on current environment 
setx env_subnet=%vpc_subnets%

// Provision stack  
cloudformation.exe create-stack --name myStack // --parameters ...

The setx variables serve as parameter overrides for correctly provisioning cloud resources.

Containerization and Microservices

For containerized apps and microservices, environment variables provide configuration outside environments:

// Pass database credentials securely
setx db_username=admin
setx db_password=%env_var%

// Populate config file
generate_config.js 

// Run container
docker run -d --env-file .env my_container

Using setx ensures credentials stay set for subsequent runs without hardcoding in containers themselves.

As you can see, setx and set both prove useful for replicating export use cases on Windows.

Common Transition Issues for Developers

When switching from a Linux development environment, developers often stumble on the following differences:

Case Sensitivity:

Linux variable names are case-sensitive by default whereas Windows ignores casing. Throws off configs expecting lower_case vs lower_case.

Paths and Delimiters:

No using colon delimiters between PATH directories on Windows. Semi-colons are standard.

Escaping Spaces:

Spaces in Windows file paths need proper escaping via quotes when assigning to variables.

Admin Access:

Setting system-wide variables often needs admin privileges on Windows machines unlike Linux.

Backslashes:

Filepaths use backslashes instead which can lead to lots of escaping.

Many developers underestimate these environmental differences when making the Linux to Windows transition. Keep them in mind as gotchas!

Conclusion

In closing, while the handy export builtin doesn‘t directly exist in Windows, setx and set achieve equivalent functionality through the Windows Command Prompt.

Developers must adapt to slight syntax variations like:

  • No export keyword
  • Semi-colons as separators
  • Double quoted strings
  • Case insensitivity

However, beyond these modest adaptations, developers can achieve similar workflows for configuring infrastructure, toolchains, builds, and deployments using persistent and temporary environment variables on Windows.

The learning curve is relatively small to replicate export capabilities thanks to setx and set commands providing wide flexibility.

Hopefully this guide has prepared you to hit the ground running configuring Windows environments coming from Linux! Let me know if any other export transition questions come up.

  • SS64
  • CMD
  • How-to

Export a JSON file of apps to a specified file.

Syntax
      WINGET export [-o] OutputFile [options]

Commands:

  -o,--output  Path to the JSON file to be created.

Options:

   -s, --source  [Optional] Specifies a source to export files from.
                 Use this option when you only want files from a specific source.

   --include-versions  [Optional] Includes the version of the app currently installed.
                       Use this option if you want a specific version.
                       By default, unless specified, import will use latest.

   --accept-source-agreements  Used to accept the source license agreement, and avoid the prompt.
   --verbose-logs              Used to override the logging setting and create a verbose log.

JSON schema

The driving force behind the export command is the JSON file. You can find the schema for the JSON file here. From the Winget Github.
The JSON file includes the following hierarchy:

Entry — Description
Sources — The sources application manifests come from.
Packages — The collection of packages to install.
PackageIdentifier — The Windows Package Manager package identifier used to specify the package.
Version [Optional] — The specific version of the package to install.

Exporting files

When the Windows Package Manager exports the JSON file, it attempts to export all the applications installed on the PC. If the winget export command is not able to match an application to an application from an available source, the export command will show a warning.

Matching an application depends on metadata in the manifest from a configured source, and metadata in Add / Remove Programs in Windows based on the package installer.

Examples

Export into myfiles.json:

C:\> winget.exe export -o \demo\myfiles.json

“I think Americans should have a policy of love. That should be the foreign policy, love. Export Love” ~ Ziggy Marley

Related commands

GitHub repository
WINGET — Discover, install, upgrade, remove and configure applications on Windows computers.
MSIEXEC — Microsoft Windows Installer.
WUAUCLT — Windows Update.


Copyright © 1999-2025 SS64.com
Some rights reserved

  • Windows equivalent of $export
  • How to export and import environment variables in windows?
  • How to export and import environment variables in windows?
  • HowTo: Set an Environment Variable in Windows — Command Line and Registry
  • Windows command line alternative for «export»
  • 2 ways to List environment variables in command line windows
  • Windows: List Environment Variables – CMD & PowerShell
  • How to Set Environment Variable in Windows

Windows equivalent of $export

People also askHow to create an environment variable in Windows?How to create
an environment variable in Windows?To Create a User Environment Variable in
Windows 10,

$ export PROJ_HOME=$HOME/proj/111
$ export PROJECT_BASEDIR=PROJ_HOME/exercises/ex1
$ mkdir -p $PROJ_HOME



SET PROJ_HOME=%USERPROFILE%/proj/111
SET PROJECT_BASEDIR=%PROJ_HOME%/exercises/ex1
mkdir "%PROJ_HOME%"

How to export and import environment variables in windows?

Add a comment. 127. I would use the SET command from the command prompt to
export all the variables, rather than just PATH as recommended above. C:\> SET
>> allvariables.txt. To import the variablies, one can use a simple loop: C:\>
for /F %A in (allvariables.txt) do SET %A. Share.

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

HKEY_CURRENT_USER\Environment



C:\> SET >> allvariables.txt



C:\> for /F %A in (allvariables.txt) do SET %A



regedit /e "%userprofile%\Desktop\my_user_env_variables.reg" "HKEY_CURRENT_USER\Environment"



set TODAY=%DATE:~0,4%-%DATE:~5,2%-%DATE:~8,2%

regedit /e "%CD%\user_env_variables[%TODAY%].reg" "HKEY_CURRENT_USER\Environment"
regedit /e "%CD%\global_env_variables[%TODAY%].reg" "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"



global_env_variables[2017-02-14].reg
user_env_variables[2017-02-14].reg



C:\> PATH > path.txt



HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment



HKEY_CURRENT_USER\Environment



@echo off
:: RegEdit can only export into a single file at a time, so create two temporary files.
regedit /e "%CD%\environment-backup1.reg" "HKEY_CURRENT_USER\Environment"
regedit /e "%CD%\environment-backup2.reg" "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"

:: Concatenate into a single file and remove temporary files.
type "%CD%\environment-backup1.reg" "%CD%\environment-backup2.reg" > environment-backup.reg
del "%CD%\environment-backup1.reg"
del "%CD%\environment-backup2.reg"



gci env:* | sort-object name | Where-Object {$_.Name -like "MyApp*"} | Foreach {"[System.Environment]::SetEnvironmentVariable('$($_.Name)', '$($_.Value)', 'Machine')"}



# export_env.ps1
$Date = Get-Date
$DateStr = '{0:dd-MM-yyyy}' -f $Date

mkdir -Force $PWD\env_exports | Out-Null

regedit /e "$PWD\env_exports\user_env_variables[$DateStr].reg" "HKEY_CURRENT_USER\Environment"
regedit /e "$PWD\env_exports\global_env_variables[$DateStr].reg" "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"



reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment">>SystemEnvVariablesSourceMachine.txt
reg query "HKEY_CURRENT_USER\Environment">>UserEnvVariablesSourceMachine.txt



(?:\A\r?\n|^HKEY_CURRENT_USER\\Environment\r?\n?|^HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment\r?\n?|^\r?\n$|\r?\n\Z)



Literally Empty



^\s+(.*?)\s{4}\w+\s{4}(.*?)$



\1=\2



SystemEnvVariablesDestinationMachine.txt
UserEnvVariablesDestinationMachine.txt



SystemEnvVariablesFinalMerge.txt
UserEnvVariablesFinalMerge.txt



(^\w+=|.*?(?:;|$))



\1\n



(.)$\r?\n



\1



Get-Content .\UserEnvVariablesFinalMerge.txt | ForEach-Object {
    $envVarDataSplit = $($_).split("=")
    if($($envVarDataSplit).count -gt 0)
    {
        Write-Output "Key: $($envVarDataSplit[0]) ~ Value: $($envVarDataSplit[1])"
        SETX $envVarDataSplit[0] "$($envVarDataSplit[1])"
    }
}



Get-Content .\SystemEnvVariablesFinalMerge.txt | ForEach-Object {
    $envVarDataSplit = $($_).split("=")
    if($($envVarDataSplit).count -gt 0)
    {
        Write-Output "Key: $($envVarDataSplit[0]) ~ Value: $($envVarDataSplit[1])"
        SETX $envVarDataSplit[0] "$($envVarDataSplit[1])" /M
    }
}

How to export and import environment variables in windows?

The first set are system/global environment variables; the second set are
user-level variables. Edit as needed and then import the .reg files on the new
machine. I would use the SET command from the command prompt to export all the
variables, rather than just PATH as recommended above. C:\> SET >>
allvariables.txt

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

HKEY_CURRENT_USER\Environment



C:\> SET >> allvariables.txt



C:\> for /F %A in (allvariables.txt) do SET %A



regedit /e "%userprofile%\Desktop\my_user_env_variables.reg" "HKEY_CURRENT_USER\Environment"

HowTo: Set an Environment Variable in Windows — Command Line and Registry

To set persistent environment variables at the command line, we will use
setx.exe. It became part of Windows as of Vista/Windows Server 2008. Prior to
that, it was part of the Windows Resource Kit. If you need the Windows
Resource Kit, see Resources at the bottom of the page. setx.exe does not set
the environment variable in the current command

1


set



1
2
3
4
5
6


ALLUSERSPROFILE=C:\ProgramData
APPDATA=C:\Users\user\AppData\Roaming
.
.
.
windir=C:\Windows



1


echo %ProgramFiles%



1


C:\Program Files



1


Get-ChildItem Env:



1
2
3
4
5
6
7
8


Name                           Value
----                           -----
ALLUSERSPROFILE                C:\ProgramData
APPDATA                        C:\Users\user\AppData\Roaming
.
.
.
windir                         C:\Windows



1


echo $Env:ProgramFiles



1


C:\Program Files



1


setx EC2_CERT "%USERPROFILE%\aws\cert.pem"



1


echo %EC2_CERT%



1


C:\Users\user\aws\cert.pem



1


setx EC2_HOME "%APPDATA%\aws\ec2-api-tools" /M



1


reg query HKEY_CURRENT_USER\Environment



1
2
3


HKEY_CURRENT_USER\Environment
    TEMP    REG_EXPAND_SZ    %USERPROFILE%\AppData\Local\Temp
    TMP    REG_EXPAND_SZ    %USERPROFILE%\AppData\Local\Temp



1


reg query HKEY_CURRENT_USER\Environment /v TEMP



1
2


HKEY_CURRENT_USER\Environment
    TEMP    REG_EXPAND_SZ    %USERPROFILE%\AppData\Local\Temp



1


reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16


HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
    ComSpec    REG_EXPAND_SZ    %SystemRoot%\system32\cmd.exe
    FP_NO_HOST_CHECK    REG_SZ    NO
    NUMBER_OF_PROCESSORS    REG_SZ    8
    OS    REG_SZ    Windows_NT
    Path    REG_EXPAND_SZ    C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\
    PATHEXT    REG_SZ    .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
    PROCESSOR_ARCHITECTURE    REG_SZ    AMD64
    PROCESSOR_IDENTIFIER    REG_SZ    Intel64 Family 6 Model 60 Stepping 3, GenuineIntel
    PROCESSOR_LEVEL    REG_SZ    6
    PROCESSOR_REVISION    REG_SZ    3c03
    PSModulePath    REG_EXPAND_SZ    %SystemRoot%\system32\WindowsPowerShell\v1.0\Modules\;C:\Program Files\Intel\
    TEMP    REG_EXPAND_SZ    %SystemRoot%\TEMP
    TMP    REG_EXPAND_SZ    %SystemRoot%\TEMP
    USERNAME    REG_SZ    SYSTEM
    windir    REG_EXPAND_SZ    %SystemRoot%



1


reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v PATH



1
2


HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
    PATH    REG_EXPAND_SZ    C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\



1


reg delete HKEY_CURRENT_USER\Environment /v USER_EXAMPLE /f



1


The operation completed successfully.



1


reg delete "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v SYSTEM_EXAMPLE /f



1


ERROR: Access is denied.



1


The operation completed successfully.



1


setx throwaway trash



1


SUCCESS: Specified value was saved.

Windows command line alternative for «export»

Windows command line alternative for «export» Ask Question Asked 4 years, 4
months ago. Modified 2 years ago. Viewed 20k times 9 1. I’ve bought a book
about Machine Learning, and it needs an environment setup. windows command-
line environment-variables. Share. Improve this question. Follow edited Mar
30, 2018 at 14:02.

$ export ML_PATH="$HOME/ml"
$ mkdir -p $ML_PATH



SET ML_PATH="$HOME/ml"
SET mkdir $ML_PATH`

2 ways to List environment variables in command line windows

set command to get environment variable list. set command in windows used to
set the environment variables for command line scope. Syntax. set
VARIABLE=path/value. Here’s an example of setting JAVA HOME to the JDK route.
set JAVA_HOME=c:\JDK1.9. `SET command also lists all environment variables.
Here simple set command print all environment

set VARIABLE=path/value



set JAVA_HOME=c:\JDK1.9



C:\>set
ALLUSERSPROFILE=C:\ProgramData
ANDROID_HOME=A:\android\sdk
ANT_HOME=A:\Java\apache-ant-1.10.0
APPDATA=C:\Users\Kiran\AppData\Roaming
ChocolateyInstall=C:\ProgramData\chocolatey
ChocolateyLastPathUpdate=132329753418192180
ChocolateyToolsLocation=C:\tools
CommonProgramFiles=C:\Program Files\Common Files
CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
CommonProgramW6432=C:\Program Files\Common Files
COMPUTERNAME=KIRAN
ComSpec=C:\WINDOWS\system32\cmd.exe
DERBY_HOME=C:\db-derby-10.14.2.0-bin
DriverData=C:\Windows\System32\Drivers\DriverData
GOOGLE_API_KEY=no



set | more



C:\>set > output.txt



C:\>set derby
DERBY_HOME=C:\db-derby-10.14.2.0-bin



Get-ChildItem Env:

Windows: List Environment Variables – CMD & PowerShell

An environment variable is a dynamic “object” containing an editable value
which may be used by one or more software programs in Windows. In this note i
am showing how to list environment variables and display their values from the
Windows command-line prompt and from the PowerShell. Cool Tip: Add a directory
to Windows %PATH% environment

C:\> set


C:\> echo %ENVIRONMENT_VARIABLE%


PS C:\> gci env:* | sort-object name


PS C:\> echo $env:ENVIRONMENT_VARIABLE

How to Set Environment Variable in Windows

Set Environment Variable in Windows via GUI. Follow the steps to set
environment variables using the Windows GUI: 1. Press Windows + R to open the
Windows Run prompt. 2. Type in sysdm.cpl and click OK. 3. Open the Advanced
tab and click on the Environment Variables button in the System Properties
window. 4.

set


Get-ChildItem Env:


echo %[variable_name]%


echo $Env:[variable_name]


setx [variable_name] "[variable_value]"


setx Test_variable "Variable value"


setx [variable_name] "[variable_value]" /M


reg query HKEY_CURRENT_USEREnvironment


reg query "HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlSession ManagerEnvironment"


reg query HKEY_CURRENT_USEREnvironment /v [variable_name]


reg query "HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlSession ManagerEnvironment" /v [variable_name]


reg delete HKEY_CURRENT_USEREnvironment /v [variable_name] /f


reg delete "HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlSession ManagerEnvironment" /v [variable_name] /f


setx [variable_name] trash

If you’re a developer, you might have encountered the «not recognized as an internal or external command, operable program or batch file» error when trying to use the export command on Windows. This guide will provide you with a step-by-step solution to fix this issue so you can continue with your development tasks.

Table of Contents

  1. Introduction to the ‘Export’ Error
  2. Step-by-Step Guide to Fix the Error
  3. Check your Environment Variables
  4. Use ‘setx’ Command in Windows
  5. Use ‘env’ Command in Git Bash
  6. FAQ
  7. Related Resources

Introduction to the ‘Export’ Error

The ‘export’ command is commonly used in Unix-based systems to set environment variables, and it’s not natively supported in the Windows Command Prompt. The error message appears when you try to use the ‘export’ command in the Command Prompt or PowerShell on a Windows machine.

To fix this issue, you can follow the steps mentioned below:

Step-by-Step Guide to Fix the Error

Check your Environment Variables

Before you start fixing the error, it’s essential to ensure that your environment variables are set correctly. You can check your environment variables by following these steps:

  1. Press Win + X and select ‘System’.
  2. Click on ‘Advanced system settings’.
  3. Click on the ‘Environment Variables’ button.
  4. Look for the specific variable that you want to set in the ‘System variables’ list.

If the variable is not available, you can add it by clicking the ‘New’ button and providing the necessary information.

Use ‘setx’ Command in Windows

To set environment variables in Windows, you can use the setx command instead of the export command. The syntax is as follows:

setx VARIABLE_NAME "VARIABLE_VALUE"

For example, if you want to set the JAVA_HOME variable, you can use the following command:

setx JAVA_HOME "C:\Program Files\Java\jdk1.8.0_291"

Note that the changes made using setx will only take effect in new command prompt instances, not in the current session.

Use ‘env’ Command in Git Bash

If you’re using Git Bash as your terminal, you can use the env command to set the environment variables similar to how it’s done in Unix-based systems. The syntax is as follows:

export VARIABLE_NAME=VARIABLE_VALUE

For example, if you want to set the JAVA_HOME variable, you can use the following command:

export JAVA_HOME="/c/Program Files/Java/jdk1.8.0_291"

FAQ

1. Why does the ‘export’ command not work in Windows?

The ‘export’ command is not natively supported in the Windows Command Prompt or PowerShell because it’s a Unix-based command. To set environment variables in Windows, you can use the setx command.

2. How can I set environment variables permanently in Windows?

You can set environment variables permanently in Windows by editing the ‘System variables’ in the ‘Environment Variables’ settings or by using the setx command.

3. How can I check the value of an environment variable in Windows?

You can check the value of an environment variable in Windows by using the echo command followed by the variable name, like this: echo %VARIABLE_NAME%.

4. Why are my changes to environment variables not taking effect in the current command prompt session?

Changes made using the setx command will only take effect in new command prompt instances. To apply the changes in the current session, you can use the set command followed by the variable name and value, like this: set VARIABLE_NAME=VARIABLE_VALUE.

5. Can I use the ‘export’ command in Git Bash on Windows?

Yes, Git Bash supports the ‘export’ command to set environment variables similar to how it’s done in Unix-based systems.

  • Git Bash for Windows
  • Microsoft Documentation: Setx Command
  • Microsoft Documentation: Environment Variables

Понравилась статья? Поделить с друзьями:
0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии
  • Docker compose для windows
  • Roblox no longer supports windows 32 bit devices что делать
  • Chmod 400 in windows
  • Как взломать учетную запись администратора windows 10
  • Пытаться соединиться с сайтами использующими шифрование гост с помощью windows sspi