Page 1 of 1

Python script not running

Posted: 2020-07-23 14:29
by DimanG
Hi everybody!

I've got a sub executing Python script over the saved message file. No result. What's wrong? Or where to look for?
There are some excessive code cause I was trying to find solution.

The message file is copied successfully, but the Python script does nothing, while running manually is ok.

Thanks in advance.

Code: Select all

Sub save_body_zc(oMessage)

   oTxtBody=oMessage.HTMLbody
   Dim StrDir, strFileName, FullName, oShell, TempDir
   
   StrDir="\\srv\EXPORT\zc\"
   TempDir="\\srv\EXPORT\zc\Temp\"
   
   strFileName = trim(oMessage.subject)
   
   FullName=StrDir & strFileName & ".eml"
   TempName=TempDir & strFileName & ".eml"
   
   With CreateObject("Scripting.FileSystemObject")
      .CopyFile oMessage.FileName, TempName, True
   End With
   
   StrDir="\\\\srv\\EXPORT\\zc\\"
   TempDir="\\\\srv\\EXPORT\\zc\\Temp\\"
   
   FullName=StrDir & strFileName & ".eml"
   TempName=TempDir & strFileName & ".eml"
   
   Set oShell = WScript.CreateObject ("WScript.Shell")
	oShell.Exec("d:\Python34\python.exe d:\Python34\Scripts\zcmail.py " & Chr(34) & TempName & Chr(34) & " " & Chr(34) & FullName & Chr(34))
   Set oShell = Nothing
   
End Sub

Re: Python script not running

Posted: 2020-07-23 15:00
by mattg
Probably the user that the hMailserver WINDOWS SERVICE runs under doesn't have the permissions required to run your python

Perhaps change the user that the Windows Service runs under

Re: Python script not running

Posted: 2020-07-28 16:29
by DimanG
Added maximal rights (local admin) to the user. Nothing changed. How can I debug the script execution? Logs contain nothing to analyze.
Manually it runs ok.

Re: Python script not running

Posted: 2020-07-28 16:51
by mattg
Press Windows start orb >> type 'services.msc'

Open Services, scroll down to hMailserver
Select hMailserver, then right click, and choose properties

Select the 'log on' tab, and screen shot that, and post screenshot here

Also show a screen shot of the properties >> Security, for the folder that has your Python installation

Re: Python script not running

Posted: 2020-07-29 17:45
by DimanG
Screenshots are in Russian. I can tell in some words: the domain user the service hMailServer runs under is a local admin. Full rights are given for it on the folder and all subfolders and files where Python is located. The script is executed manually under this user with success. But what's inside hMailServer - I can't find out. Only message file is copied to another location - I did so when the script stopped working (it worked some days, and nothing was changed in the system).

Re: Python script not running

Posted: 2020-07-30 02:34
by mattg
Try adding some event logging to your hmailserver script

like
EventLog.Write(TempName)

just before the python script is called to make sure that the variables are set correctly

Re: Python script not running

Posted: 2020-08-03 22:22
by DimanG
Tried several logging events in vbs, py and cmd scripts and found out that everything is ok with variables, but the cmd-script doesn't run at all. The hMailserver log is always full of Script Error records with some unknown codes. Is there any way to see what's wrong with of WScript.Shell Exec command?

Thank you for help

Re: Python script not running

Posted: 2020-08-04 00:09
by DimanG
Last example:
"ERROR" 7560 "2020-08-04 00:47:02.259" "Script Error: Source:

Re: Python script not running

Posted: 2020-08-04 10:52
by SorenR
I don't use Python but how about this?

Code: Select all

Sub save_body_zc(oMessage)

    Dim StrDir, strFileName, FullName, WshShell, oExec, TempDir

    StrDir="\\srv\EXPORT\zc\"
    TempDir="\\srv\EXPORT\zc\Temp\"

    strFileName = trim(oMessage.subject)

    FullName=StrDir & strFileName & ".eml"
    TempName=TempDir & strFileName & ".eml"

    With CreateObject("Scripting.FileSystemObject")
        .CopyFile oMessage.FileName, TempName, True
    End With

    FullName=Replace(FullName, "\", "\\")
    TempName=Replace(TempName, "\", "\\")

    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set oExec = WshShell.Exec("d:\Python34\python.exe d:\Python34\Scripts\zcmail.py " & Chr(34) & TempName & Chr(34) & " " & Chr(34) & FullName & Chr(34))

    Do While oExec.Status = 0
        WshShell.Run "powershell Start-Sleep -Milliseconds 100", 0, True
    Loop

    EventLog.Write("Return code on d:\Python34\python.exe d:\Python34\Scripts\zcmail.py " & Chr(34) & TempName & Chr(34) & " " & Chr(34) & FullName & Chr(34) & " was " & oExec.Status)
    Set oExec = Nothing
    Set WshShell = Nothing

End Sub

Re: Python script not running

Posted: 2020-08-15 21:40
by DimanG
After reading some Russian sources I've tried this:

CreateObject("Wscript.Shell").Run "d:\Python34\Scripts\zcmail1.cmd " & Chr(34) & strFileName & ".eml" & Chr(34), 0

and it works!

Thanks to everybody for your attention and participation.

PS: VBS syntaxis - is a dreadful thing...