0

I just want to enter integrate these two commands from cmd and use them in a python script, but I'm novice in both programming and python. How I can achieve this?

cd C:\
python dumpimages.py http://google.com C:\images\
2
  • 2
    Incidentally - my telepathic spider-sense is telling me you might be trying to save images from a webpage. Have you considered using GNU wget for that? Commented Apr 21, 2012 at 12:10
  • I'm just trying to download changing images whose url is hidden. It's not a lot of pictures on the page, so I found this script. stackoverflow.com/questions/257409/…. More than needed, but it works. Commented Apr 21, 2012 at 12:28

3 Answers 3

2

Use the os.subprocess module.

Note that exec() will also work but it is deprecated in favour of os.subprocess.

Further to my comment above, if all you want to do is retrieve images from a webpage, use GNU wget with the -A flag:

wget -r -P /save/location -A jpeg,jpg,bmp,gif,png http://www.domain.com
Sign up to request clarification or add additional context in comments.

2 Comments

Oh nice, I shall try this now! Thanks!
Note: the -r flag is for 'recursive' - probably only need -p for page display prerequisites. (Consult man wget for more information.)
0

I suspect the cd C:\ is not necessary, and once that's gone all you seem to be asking for is a way to launch a python script.

Perhaps all you want is to modify saveimage.py so that it has the hard-coded arguments you want? I don't know what that script is--maybe you can tell us if it's important or you aren't allowed to modify it.

2 Comments

It's Greg Hewgill's script from here: stackoverflow.com/questions/257409/… Trying to download images from a hidden url. There's only one or two pictures on the page, so I'm using this script because it was quick.
0

I think you are looking for sys.argv

Try:

import sys
print(sys.argv)

on top of your saveimage.py.

It should print something like:

['C:\saveimage.py', 'http://google.com', 'C:\images\']

You see, sys.argv is a list of strings. The first item is the name of the script itself, the others are the parameters. Since lists are 0-based, you can access the i-th parameter to the script with sys.argv[i]

1 Comment

Thanks, it's on top of the script already. I'm just trying to combine two scripts into one.

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.