in Education by
The java project I am working on has a .bat file and a .sh file which build the CLASSPATH for the project to run. (.bat for windows and .sh for the rest). Now, I am writing a python script that needs access to the classpath created by these scripts, the one from .sh if on linux and the one from .bat if on windows. Currently, I am doing this for linux: Popen(['bash', '-c', '. mkcp.sh && echo $CLASSPATH'], stdout=sp.PIPE).communicate()[0].strip() And I can't figure out an equivalent way to do this on windows. So far I've come up with this check_output(['cmd', '/c', 'call mkcp.bat && echo %CLASSPATH%']) But that puts all the commands in the mkcp.bat file into the stdout. (Adding @echo off to that file is not an option for me, i.e., I can't modify it). That problem aside, the main problem is that the %CLASSPATH% is substituted with its value before the batch file is run, which is not what I want. Another approach I thought of was if I create a Popen object as above and run the batch file and if I can access the environment of that process, I can get what I want. But from Popen's documentation, this doesn't look to be possible. Any ideas on how to achieve this? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
The simplest way would be to create a batch file with the relevant commands. That way the variable doesn't get expanded until CMD processes the relevant line. Also use @echo off to disable echo: @echo off call mkcp.bat echo %CLASSPATH% Then just call that batch file from your Python code. If you want to do it without an intervening batch file try: check_output(['cmd', '/V:ON', '/c', '"@echo off && call mkcp.bat && echo !CLASSPATH!"']) /V:ON enables delayed expansion of environment variables when you use ! for the substitution instead of %.

Related questions

0 votes
    The java project I am working on has a .bat file and a .sh file which build the CLASSPATH for ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 17, 2022 in Education by JackTerrance
0 votes
    I am trying to run a .bat file in a new window so the user of the PC can input commands, ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    Slide Rule allowed the operator to multiply, divide and calculate square and cube roots by moving the rods ... constructed boards. Select the correct answer from above options...
asked Dec 10, 2021 in Education by JackTerrance
0 votes
    An infinite ladder is constructed with 1 Ω and 2 Ω resistor shown below. The current I flowing through the circuit ... GATE EC Exam, Network Theory MCQ (Multiple Choice Questions)...
asked Oct 12, 2021 in Education by JackTerrance
0 votes
    What are the advantages of piers constructed monolithically with the bridge deck over usage of bearings?...
asked Jan 1, 2021 in Technology by JackTerrance
0 votes
    In the construction of a two-span bridge (span length = L) by using span-by-span construction, why is a ... .25L bridge segment is constructed in the first phase of construction?...
asked Jan 1, 2021 in Technology by JackTerrance
0 votes
    I installed PEAR and when I try to run it, I receive this message: PHP_PEAR_PHP_BIN is not set correctly ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 26, 2022 in Education by JackTerrance
0 votes
    Distinguish between butterfly and bat with the help of four distinguish properties. Select the correct ... proposed by,electromagnetic theory engineering physics,Science nptel...
asked Nov 7, 2021 in Education by JackTerrance
0 votes
    Bat is included in which class? 1. Amphibia 2. Reptilia 3. Aves 4. Mammalia Select the ... Science,Science proposed by,electromagnetic theory engineering physics,Science nptel...
asked Nov 7, 2021 in Education by JackTerrance
0 votes
    Choose the correct alternative and write its alphabet against the sub-question number: i. .. ... ,Science proposed by,electromagnetic theory engineering physics,Science nptel...
asked Nov 7, 2021 in Education by JackTerrance
0 votes
    I migrated to Android Studio 3 and Gradle 4. Then I changed compile to implementation in my build.gradle ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I'm using Kotlin to build a web service and I stumbled upon what I consider to be a strange ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 17, 2022 in Education by JackTerrance
0 votes
    What exactly is classpath, what value does it hold ? Can you also tell me the command that can be used to set classpath ? Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
0 votes
    How can we add stuff to the classpath when running things in groovy or groovysh?...
asked Sep 25, 2021 in Technology by JackTerrance
0 votes
    Is it necessary to keep Spring MVC in the classpath for developing RESTful web services?...
asked Jun 24, 2021 in Technology by JackTerrance
...