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\
geekchap
  • 3
  • 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](http://www.gnu.org/software/wget/) for that? – Li-aung Yip Apr 21 '12 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. http://stackoverflow.com/questions/257409/download-image-file-from-the-html-page-source-using-python. More than needed, but it works. – geekchap Apr 21 '12 at 12:28

3 Answers3

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
Community
  • 1
  • 1
Li-aung Yip
  • 12,320
  • 5
  • 34
  • 49
  • Oh nice, I shall try this now! Thanks! – geekchap Apr 21 '12 at 12:42
  • Note: the `-r` flag is for 'recursive' - probably only need `-p` for `page display prerequisites`. (Consult [`man wget`](http://linux.die.net/man/1/wget) for more information.) – Li-aung Yip Apr 21 '12 at 12:46
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.

John Zwinck
  • 239,568
  • 38
  • 324
  • 436
  • It's Greg Hewgill's script from here: http://stackoverflow.com/questions/257409/download-image-file-from-the-html-page-source-using-python 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. – geekchap Apr 21 '12 at 12:30
  • [You would be better off using `wget`.](http://stackoverflow.com/questions/4602153/how-do-i-use-wget-to-download-all-images-into-a-single-folder) – Li-aung Yip Apr 21 '12 at 12:36
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]

ch3ka
  • 11,792
  • 4
  • 31
  • 28