Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8371935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:17:04+00:00 2026-06-09T14:17:04+00:00

I have a program the launches a cmd console with a certain environment. The

  • 0

I have a program the launches a cmd console with a certain environment. The problem the console is launched by clicking a button, so I can’t create a custom launcher on my own with that environment.

What I want:
Given a file with a set variables (generated by running set command in the custom launched cmd), I want to set up the environment in the current cmd console by reading that file.

Example:

in.txt (note the spaces in same vars on the right side):

var1=c:\program files
path=c:\;c:\bin
var2=d:\folder with libs  

After running the script like: ./script.sh in.txt the environment in the current cmd console should be (output after running set command):

var1=c:\program files
path=c:\;c:\bin
var2=d:\folder with libs

Note: bash scripting can be used inside the script as long as the environment is set right.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T14:17:06+00:00Added an answer on June 9, 2026 at 2:17 pm

    I have manged to write the following working script:

    • Usage: script.bat file_name
    • If file_name not provided prints usage
    • Creates a backup file envbkp.bat with environment variables before deleting them for possible restore

      @echo off
      
      set _exitStatus=0
      set _argcActual=0
      set _argcExpected=1
      
      echo.
      
      for %%i in (%*) do set /A _argcActual+=1
      
      if %_argcActual% NEQ %_argcExpected% (
          call :_ShowUsage %0%
          set _exitStatus=1
          goto:_EOF
      )
      
      set _exitStatus=
      set _argcActual=
      set _argcExpected=
      
      if exist ".\envbkp.bat" del ".\envbkp.bat"
      echo @echo off > envbkp.bat
      for /f "tokens=1* delims==" %%a in ('set') do (
          echo set %%a=%%b>> .\envbkp.bat
          set %%a=
      )
      
      for /f "tokens=1* delims==" %%a in ('type %~1') do (
          set %%a=%%b
      )
      goto:_EOF
      
      :_ShowUsage
          echo [USAGE]: %~1 env_file
          echo.
      if NOT "%~2" == "" (
          echo %~2
          echo.
      )
      goto:eof
      
      :_EOF
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have program, that must interact with a console program before my program can
We have our custom setup.exe program which launches a series of individial MSIs in
I have code that launches a program: Process.Start(cmd.exe, /c test.exe \\ > output.txt).WaitForExit(); Although
I have a java program that launches a program on start up. This can
I have a program app1 which launches another application using: app2Server := CreateOleObject('app2.Server'); On
I have the following c program which launches a Gtk Program on ubuntu: #include
I have a main class in a program that launches another class that handles
I have a small launcher program, it loads a Splash screen on it's own
I have a Java program that is launched by a batch file with a
I have seen lately a couple of programs that can be launched as daemons

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.