[Tutor] Calling Python Functions from Powershell scripts

Christian Witts cwitts at compuscan.co.za
Wed Oct 5 09:57:17 CEST 2011


On 2011/10/05 09:32 AM, Nikunj Badjatya wrote:
>
> Howdy All,
>
> To give an overview of the problem,
> I have an installer. It is used to install virtual machines at 
> specific location.
> The installer is written in Powershell and Python. The topmost script 
> is in
> Python ( install.py ) which internally calls other .py and .PS1 ( 
> powershell ) scripts using popen() .
> I am working on having a file based logging mechanism for this 
> installer. i.e both for .py and .PS1 scripts.
>
> Q1. I want to use python logging module. But then how do I integrate 
> it with powershell scripts. ?
> One option would be to write into a .log file using logging module in 
> all .py scripts. Use that ( .log ) file
> in powershell scripts by using its own logging module ( dnt knw if it 
> exists ! )
>
> Q2. Can we call / run  .py from inside .PS1. ?
>
> Please suggest suitable methods for effective logging mechanism.
>
> Thanks
>
> Nikunj
> Bangalore
>
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

PowerShell has built-in cmdlets for logging that use the verb "write".  
Running the command "get-command write*" will list those commands for 
you (and a couple of other ones).  Each one is controlled by a shell 
variable that ends with "Preference". For example, to turn the warning 
messages up, then set the variable $WarningPreference to "Continue". 
Other options are Stop, Inquire, and SilentlyContinue. To turn down 
logging, set each of the $*Preference session variables to 
"SilentlyContinue". To turn up logging, then set them all to "Continue".

Here are some references for automatic logging [1] and a script template 
with a logging function [2]

[1] http://jdhitsolutions.com/blog/2011/03/powershell-automatic-logging/
[2] http://powershell.com/cs/media/p/3950.aspx

-- 

Christian Witts
Python Developer

//
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111005/8399a642/attachment.html>


More information about the Tutor mailing list