Something wrong in my Python script/Powershell usage?

0

So I am trying to programmatically add printers, and I'm getting a 0x00000709 error.

What could cause this? I'm suspecting something in my code might be a little off:

import subprocess
def printerSetup(printer):
    subprocess.call(r'Cscript c:/windows/System32/Printing_Admin_Scripts/en-US/Prnport.vbs -a -r "' + printer + '.print.mediag.com" -h "' + printer + '.print.mediag.com" -o raw')
    if printer == 'jupiter':
        subprocess.call(r'rundll32 printui.dll, PrintUIEntry /if /b "' + str.title(printer) + '" /u /y /f w:\printers\\toshibae3511\eng\est_c2.inf /r "' + printer + '.print.mediag.com" /m "TOSHIBA e-STUDIO Color PS3"')
    elif printer == 'saturn' or printer == 'neptune':
        subprocess.call(r'rundll32 printui.dll, PrintUIEntry /if /b "' + str.title(printer) + '" /u /f w:\printers\\toshibae3511\eng\est_c2.inf /r "' + printer + '.print.mediag.com" /m "TOSHIBA e-STUDIO Color PS3"')  
    elif printer == 'mercury':
        subprocess.call(r'rundll32 printui.dll, PrintUIEntry /if /b "' + str.title(printer) + '" /u /f w:\printers\dell1720\drivers\print\dell1720\DKABJ740.inf /r "' + printer + '.print.mediag.com" /m "Dell Laser Printer 1720dn"')
    elif printer == 'sonic' or printer == 'pangea':
         subprocess.call(r'rundll32 printui.dll, PrintUIEntry /if /b "' + str.title(printer) + '" /u /f w:\printers\HPUniversalPS_x64\hpcu112v.inf /r "' + printer + '.print.mediag.com" /m "HP Universal Printing PS"')

printerList = ["neptune", "saturn", "mercury", "jupiter", "sonic", "pangea"]

for x in printerList:

    printerSetup(x)

Now each of these printers is for sure added to the network, and I am calling the print script for Windows - could it be something with my list?

python
powershell
asked on Stack Overflow May 14, 2012 by Steven Matthews

1 Answer

0

You have to pass a list:

subprocess.call(['Cscript', r'c:/windows/System32/Printing_Admin_Scripts/en-US/Prnport.vbs', '-a', ...])

Also check quotes...

Take a look at http://docs.python.org/library/subprocess.html?highlight=subprocess#subprocess.check_call

answered on Stack Overflow May 14, 2012 by f p • edited May 14, 2012 by f p

User contributions licensed under CC BY-SA 3.0