Re: [python-win32] subprocess and stdout

2009-07-27 Thread Dave Angel

Christopher Chapman wrote:

I'm trying to write a "module" to a larger program.  This module eventually
needs to reference a config file with setup information in it, but I'm not
there yet.  I'm using the subprocess module to run an external antivirus
program and trying to get the output written to a log file, but I keep
getting a weird return.  My code is listed below.  I'm a noob to Python so
I'm not sure if this is a windows specific issue or not, but I'm programming
on windows and more then likely what I'm working on won't be on anything
other then a windows machine.  I'm also writing my code for 3.1 if that
makes any difference.

# Pass target path to scanners command line and write output to a file
# Currently "scan" only targets the McAfee Command Line Scanner
print() 
print ("Begining scan of " + target)

print()
scan = "scan /all " + target
s = subprocess.Popen(scan,
 stdout=subprocess.PIPE)
out = s.communicate()[0]
chgout = str(out)
s.wait()
scanlog.write(chgout)
scanlog.close
"
If I change my stdout in s subprocess to None then everything gets written
to the terminal as if I had just run the program straight from the command
line, but when I try piping it to my file "scanlog" then literally the only
return I get in the file is '' or two single quotes.  I've even tried piping
the output and then printing it instead of writing it to a file and I get
the same result.  I've experimented with standard windows command line
commands and using the same syntax was able to pipe directory listings and
other things to my file.  Any ideas what I'm missing here?  Thanks in
advance

Chris Chapman


  
I suspect it's because of the way the antivirus program is written.  I 
can't be sure what you tried at the command prompt, but have you tried this:


c:\>scan /all > scanlog.txt


If this does not capture to the file, then scan.exe isn't written in the 
way you're expecting.  There are several ways to write directly to a 
console that do not redirect or pipe.


You might also look to see whether scan has any other commandline 
options.  One of them might be to create a log file.


DaveA
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Problem with Python win32com while loading facebook homepage

2009-07-27 Thread Mike Driscoll

Adrien,

Hi dear members of the python-win32 python mailing list,

I'm trying to connect to my facebook account.. I'd like to automate 
some tasks like closing applications requests, and why not automate 
task for application games of facebook, if I arrive to do this.


But I can't arrive to connect to homepage..
First, without win32com, the code page return by the script was a 
javascript script :



(function(loc) { if (loc.pathname == '/') { return; } var uri_re =
/^(?:(?:[^:\/?#]+):)?(?:\/\/(?:[^\/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?/;
var target_domain = ''; loc.href.replace(uri_re, function(all,
path, query, frag) { var dst, src; dst = src = path + (query ? '?'
+ query : ''); if (frag) { if (frag.charAt(0) == '/') { dst =
frag.replace(/^\/+/, '/') .replace(/_fb_qsub=([^&]+)&?/,
function(all, domain){ if (domain.substring(domain.length - 13) ==
'.facebook.com <http://facebook.com>') { target_domain =
'http://'+domain; } return ''; }); } else if (/&|=/.test(frag)) {
var q = {}; var m = frag.match(/([^#]*)(#.*)?/); var arr =
(query||'').split('&').concat((m[1]||'').split('&')); for (var
i=0, length=arr.length; ihttp://www.facebook.com>\/common\/browser.php");



After reading a little on the web ( I searched a solution to execute 
javascript code from python), I've found the next added lines, which 
use win32com. I have installed pywin32-214 (I use python 2.6.2).


See below my code :

# -*- coding:Utf-8 -*-
#!/usr/bin/python
import httplib
import urllib

Connexion = httplib.HTTP('www.facebook.com ')
Connexion.putrequest('GET', '/home.php')
Connexion.putheader('Host', 'www.facebook.com
')
Connexion.putheader('Accept', 'text/html')
Connexion.putheader('Cookie', 'the_long_cookie_from_facebook')
Connexion.endheaders()
ErrCode, ErrMsg, Headers = Connexion.getreply()
Handle = Connexion.getfile()
Buffer = Handle.read()

from win32com.client.gencache import EnsureDispatch
ie = EnsureDispatch('InternetExplorer.Application')
ie.Navigate('http://www.facebook.com')
print ie.Document.documentElement.innerHTML

 
When I execute the script, I have this error :


>>>
Traceback (most recent call last):
  File "C:\Documents and
Settings\adlemair\Bureau\exos\connectFacebook.py", line 18, in

from win32com.client.gencache import EnsureDispatch
  File "C:\Python26\lib\site-packages\win32com\__init__.py", line
5, in 
import win32api, sys, os
ImportError: DLL load failed: Le module spécifié est introuvable.


Do you know why ? Do you arrive to execute this script on your side ?


Thank you so much for your advise

Best regards,

Why not just use the pyFacebook module? It wraps Facebook's API and 
would probably be more reliable for communicating with their services. 
Here's a link: http://wiki.developers.facebook.com/index.php/Python


- Mike
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


[python-win32] By-reference COM method arguments not being treated as outputs

2009-07-27 Thread Mike Graham
I used MakePy on a COM library with some success, but it does not seem
to work with methods with passed-by-reference arguments. The
documentation, as I understand it, says that the c_fun(in1, in2,
*out1, *out2) should transform into (out1, out2) = py_fun(in1, in2).

For example, MakePy makes me the method

def PickObject(self, obj=defaultNamedNotOptArg,
x=defaultNamedNotOptArg, y=defaultNamedNotOptArg,
z=defaultNamedNotOptArg
, obj_num=defaultNamedNotOptArg, 
entity_num=defaultNamedNotOptArg,
tolerance=9.997473787516e-06, PType=0):
"""Retrieve an object ID and face or edge number by giving an 
object
type and global coordinates"""
return self._ApplyTypes_(76, 1, (24, 0), ((16387, 3), (12, 1), 
(12,
1), (12, 1), (16387, 3), (16387, 3), (5, 49), (3, 49)), u'PickObject',
None,obj
, x, y, z, obj_num, entity_num
, tolerance, PType)

where obj_num and entity_num are outputs. I cannot call this with
object.PickObject(10, 0, 0, 0) like I should be able to or with
object.PickObject(10, 0, 0, 0, pythoncom.Empty, pythoncom.Empty),
which I've seen suggested (or with anything else I've tried in the
last spots).

How do I get this to treat these arguments right?
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] By-reference COM method arguments not being treated as outputs

2009-07-27 Thread Greg Antal

Mike:

When I ran into this, it was because the type library on which I ran 
makepy was not quite correctly defined.  You could check the archives of 
this mailing list starting at


http://www.mail-archive.com/python-win32@python.org/msg05578.html

to see if maybe you have the same problem.  If so, go to the next item 
in the thread to see Mark Hammond's suggested workaround.  That worked, 
and would have been fine with me, but the TLB's authors actually fixed 
the TLB as soon as I showed them the problem, so I didn't have to do 
anything funny.


Good luck.

- Greg Antal

Gregory W. Antal
Senior Technical Advisor
ATA Engineering, Inc.
11995 El Camino Real, Suite 200 
San Diego, CA  92130
www.ata-e.com

greg.an...@ata-e.com
858-480-2072  (Phone)
858-792-8932  (Fax)



Mike Graham wrote, On 7/27/2009 12:30 PM:

I used MakePy on a COM library with some success, but it does not seem
to work with methods with passed-by-reference arguments. The
documentation, as I understand it, says that the c_fun(in1, in2,
*out1, *out2) should transform into (out1, out2) = py_fun(in1, in2).

For example, MakePy makes me the method

def PickObject(self, obj=defaultNamedNotOptArg,
x=defaultNamedNotOptArg, y=defaultNamedNotOptArg,
z=defaultNamedNotOptArg
, obj_num=defaultNamedNotOptArg, 
entity_num=defaultNamedNotOptArg,
tolerance=9.997473787516e-06, PType=0):
"""Retrieve an object ID and face or edge number by giving an 
object
type and global coordinates"""
return self._ApplyTypes_(76, 1, (24, 0), ((16387, 3), (12, 1), 
(12,
1), (12, 1), (16387, 3), (16387, 3), (5, 49), (3, 49)), u'PickObject',
None,obj
, x, y, z, obj_num, entity_num
, tolerance, PType)

where obj_num and entity_num are outputs. I cannot call this with
object.PickObject(10, 0, 0, 0) like I should be able to or with
object.PickObject(10, 0, 0, 0, pythoncom.Empty, pythoncom.Empty),
which I've seen suggested (or with anything else I've tried in the
last spots).

How do I get this to treat these arguments right?
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32
  

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32