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

  • SEARCH
  • Home
  • 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 9105243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:03:30+00:00 2026-06-17T02:03:30+00:00

Is it possible to run a batch file under windows as if it were

  • 0

Is it possible to run a batch file under windows as if it were running from the same shell that was running the java instance (as opposed to in a new console instance)?

There is a batch file that I want to run that is provided by a third party and sets a bunch of environment variables conditionally that I would much rather not have to translate into Java, but that are needed for certain things in the Java app to work.

I know the alternative is to manually run the batch file in a command prompt before running the Jar to get the same effect, but in this scenario that would require either a lot of typing or a lot of customized batch files.

  • 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-17T02:03:32+00:00Added an answer on June 17, 2026 at 2:03 am

    Short answer: no.

    When you state “running from the same shell that was running the java instance” you seem to suggest that the shell & java are co-existing at some common/shared level. Their relationship is, instead, hierarchical: the shell is a parent process, and it started java as a child process.

    Any changes that a process makes (such as your batch process) to the environment are:

    • visible to that process, and
    • visible to child processes, but
    • never to a parent process.

    The reason the batch file, when executed from the command prompt, causes immediate changes to the current environment is that the command shell (cmd.exe) is designed to process batch files “in place” – without starting a new process [under unix, the shell would “source” a script file to do much the same thing].

    Java, not being “cmd.exe”, doesn’t do this. As you’ve noted, running a batch file from java will create a new command processor as a child process, which on completion has no effect on the java environment.

    Options include:

    1. Write a batch file to
      • call your other batch file, then
      • start your java process, OR
    2. Parse the batch file by your java program. If you “mandate” that the only valid content of your “batch file” are simple assignment statements of the form “X=Y”, then this isn’t too difficult – you might in fact load it as a Properties file.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How do I run a batch file from my Java Application? Are
Is it possible to run a windows xp bat script remotely from a ubuntu
Is it possible to run any Command Line based program or batch file and
I wanted to run a .cmd file from Java. I have something which works
I'm running a test script from batch file. Because it is test, the programs
I have created a batch file for ex(ex.bat) Is it possible to run batch
I'm trying to write a Windows batch file that kicks off a setup program
I want to run Batch file 1(Path C:\3rdparty\Test\App) from Batch file 2(C:) and VS2008.sln
How can I run a windows batch file but hiding the command window? I
Is there a way for a batch file (in this case, running on Windows

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.