1

I have two scripts, the first, mail.py, scrapes hyperlinks from emails. The second, scrape.py, scrapes data from the links using Selenium and BeautifulSoup.

I have been using os.system('start cmd /c python scrape.py '+ link + ' && exit') to run scrape.py when a new email with a link arrives.

Sometimes I get an error with scrape.py but when I run it by manually inserting the link it works ok.

I'm new to python and I've read that os.system can be unstable. Is that correct? Is it likely to be the cause of the problem?

I'm under time pressure to finish the project so would prefer to keep the code as is unless that is the cause.

3
  • 4
    This is an insane command to run. You're telling an instance of cmd to run start, which will run cmd again, which will run python. Why not just run python directly? Commented Jul 14, 2021 at 15:03
  • 3
    If at all feasible, you should refactor your code so you can simply import it. There are situations where it's useful or even necessary to run Python as a subprocess of itself, but this does not seem to be one of them. Commented Jul 14, 2021 at 15:14
  • Thanks guys. I did it this way in case a new email arrived whilst scrape.py was still scraping a previous email link. Commented Jul 14, 2021 at 15:38

1 Answer 1

2

You can try to run the python script without call cmd:

os.system('python scrape.py '+ link)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.