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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:42:30+00:00 2026-05-25T02:42:30+00:00

I am writing a script that calls another java program, to perform some tasks.

  • 0

I am writing a script that calls another java program, to perform some tasks. It is very important that each task starts, if and only if, the previous one has finished. Each task might run for several days, producing a huge amount of output. It works on a huge database

I noticed that if I run the script using os.system(), it runs for several minutes the first task and then for some reason starts the second one, although the first task is not complete. The first task doesn’t end normally it’s like it suddenly stopped working. If i try it on a smaller database which it takes only few minutes to process, everything works fine.

I don’t understand why it behaves this way!

For this reason I was trying to use Popen() so I can use the communicate() in order to make wait till the end of the process called.

For some reason the same command to call the external java program works with os.system(), while it says that it cannot find the main() with Popen(). I am using relative paths, I tried absolutes path too with no luck.

Is there an alternative to the Popen()? However, I don’t understand why it cannot find the main class. What is exactly the difference between os.system() and Popen() when calling an external program? How can I solve or workaround my problem?

here is the code:

import os
from subprocess import Popen

def doWork():

    owd = os.getcwd()
    cmd = "java -Dfile.encoding=Cp1252 -classpath \"bin;lib\\mysql-connector-java-5.0.8-bin.jar;lib\\sqlitejdbc-v056.jar\" core.ODBManager"
    os.chdir("ODBManager")

    #this way does not work
    p = Popen(cmd + "1", shell=True) #import
    p.communicate() #now wait

    p = Popen(cmd + "2", shell=True) #convert
    p.communicate() #now wait

    p = Popen(cmd + "3", shell=True) #export
    p.communicate() #now wait

    #this way works but does not wait the command to finish
    #before starting another one
#   os.system(cmd+" 1") #import
#   os.system(cmd+" 2") #convert
#   os.system(cmd+" 3") #export

    os.chdir(owd)

thank you. If something is not clear, feel free to ask.
P.S. the java program (build with eclipse) is in a subfolder and it reads some input from a file which is in another subfolder so I had to go with chdir, otherwise couldn’t find that file.

  • 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-05-25T02:42:31+00:00Added an answer on May 25, 2026 at 2:42 am

    Not sure if this is a typo, but in the way “that does not work” as you describe it, you have no space between the cmd and the concatenated “1”, “2” and “3” strings. With the os.system calls you do have the space. Without the space you are effectively changing the name of the class whose main method you want to execute and therefore you get the error reported.

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

Sidebar

Related Questions

I'm writing a bash script which calls a lot of other scripts. Several scripts
I am writing a simple commandline script that uses raw_input, but it doesn't seem
I have one main thread that does some rather CPU intensive operation. The thread
I am writing an application that will call a SQL Server job on all
I am writing a perl script, and in the part where I am checking
I'm writing a profile-based image downloader, and it's structured in multiple files: lib/ profiles/
I'm writing the wrong syntax, so the function is not getting called. I'm making
I experimenting with writing Vista/W7 gadgets. In my experiment I want to write the
I have a simple enough web application. I want to measure for any day
I have written a Perl XS wrapper for a C library consisting of about

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.