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 8982667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:38:12+00:00 2026-06-15T20:38:12+00:00

I have the python code which will download the .war file and put it

  • 0

I have the python code which will download the .war file and put it in a path which is specified by the variable path.

Now I wish to extract a specific file from that war to a specific folder.

But I got struck up here :

os.system(jar -xvf /*how to give the path varible here*/  js/pay.js)

I’m not sure how to pass on the variable path to os.system command.

I’m very new to python, kindly help me out.

  • 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-15T20:38:13+00:00Added an answer on June 15, 2026 at 8:38 pm

    If you really want to use os.system, the shell command line is passed as a string, and you can pass any string you want. So:

    os.system('jar -xvf "' + pathvariable + '" js/pay.js)
    

    Or you can use {} or %s formatting, etc.

    However, you probably do not want to use os.system.

    First, if you want to run other programs, it’s almost always better to use the subprocess module. For example:

    subprocess.check_call(['jar', '-xvf', pathvariable, 'js/pay.js'])
    

    As you can see, you can pass a list of arguments instead of trying to work out how to put a string together (and deal with escaping and quoting and all that mess). And there are lots of other advantages, mostly described in the documentation itself.

    However, you probably don’t want to run the war tool at all. As jimhark says, a WAR file is just a special kind of JAR file, which is just a special kind of ZIP file. For creating them, you generally want to use JAR/WAR-specific tools (you need to verify the layout, make sure the manifest is the first entry in the ZIP directory, take care of the package signature, etc.), but for expanding them, any ZIP tool will work. And Python has ZIP support built in. What you want to do is probably as simple as this:

    import zipfile
    with zipfile.ZipFile(pathvariable, 'r') as zf:
        zf.extract('js/pay.js', destinationpathvariable)
    

    IIRC, you can only directly use ZipFile in a with statement in 2.7 and 3.2+, so if you’re on, say, 2.6 or 3.1, you have to do it indirectly:

    from contextlib import closing
    import zipfile
    with closing(zipfile.ZipFile(pathvariable, 'r')) as zf:
        zf.extract('js/pay.js', destinationpathvariable)
    

    Or, if this is just a quick&dirty script that quits as soon as it’s done, you can get away with:

    import zipfile
    zf = zipfile.ZipFile(pathvariable, 'r')
    zf.extract('js/pay.js', destinationpathvariable)
    

    But I try to always use with statements whenever possible, because it’s a good habit to have.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with a CSV file in python, which will have ~100,000 rows when
I have a project that has code which will communicate with a python script
I have created some python code which creates an object in a loop, and
Guys, I have much python code in modules which are resides in several python
I have some python code which generates a 256^3 numpy array of data that
I have simple Z3 python code like below. I expect the print line will
I have created some Python code which is really complicated but it basically asks
I have python code below that will loop through a table and print out
I need to extend a python code which has plenty of hard coded path
I'm thinking how to arrange a deployed python application which will have a Executable

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.