Jump to content

Called script hangs in C


Recommended Posts

Hi,

I have a front end AutoIt3 script which calls _INetSmtpMail which uses command line input.

This script works perfectly well from a DOS prompt or DOS batch file (and is not interactive).

However, when I call this compiled AutoIt3 script from within a C script, the email is sent, but that is the last thing the C script does. It seems the AutoIt3 script hangs and does not return back to the C script.

Any ideas why C stops responding?

One other thing, when running the script from DOS, it can write to a remote log file. Called from C, the logging stops too. Makes debugging difficult indeed!

Link to comment
Share on other sites

Have you tried replacing your AutoIt script with a simple debug line like:

MsgBox(0, "", "")

Compile and call that from within your C code.

If that code "hangs" then you know it is not _INetSmtpMail

...sorry if you have already tired something like this - it all that I can think to try ATM.

You might also want to post a sample of you C code along with part of your AutoIt code... maybe there is something in the code that someone smarter than I can spot. :-)

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Have you tried replacing your AutoIt script with a simple debug line like:

MsgBox(0, "", "")

Compile and call that from within your C code.

If that code "hangs" then you know it is not _INetSmtpMail

...sorry if you have already tired something like this - it all that I can think to try ATM.

You might also want to post a sample of you C code along with part of your AutoIt code... maybe there is something in the code that someone smarter than I can spot. :-)

Thanks for your reply.

I tried a msgbox() before and after the call to _INetSmtpMail and neither appeared. Like the logging to file function does not work, it seems the C shell is stopping any interaction?

As this script works fine from DOS prompt and DOS batch, the problem must be something to do with C, so perhaps this is the wrong forum to log this call.

Link to comment
Share on other sites

I would have only the one line of AutoIt code in your test/debug script - just the MsgBox. Let the command line info that you pass to the script just go nowhere. If the MsgBox does not appear - then I would say that it must be the C code.

You can always post your C code in the chat forum

...plenty of members know C...

...just not me...

-MSP-

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Ok, here is the C code ....

cmdSMTP.exe is the compiled AutoIt3 script

sprintf(cmnd, "cmdSMTP.exe %s %s %s %s %s", fromName, fromAddress, toAddress1, subject4, monFailMessage[t]);
system(cmnd);

Here is the front end for _INetSmtpMail ...

#include <INet.au3>
Func _FileAppend( $sFilePath, $sText )
;==============================================
; Local Constant/Variable Declaration Section
;==============================================
  Local $hOpenFile
  Local $hWriteFile

  $hOpenFile = FileOpen( $sFilePath, 1 )

  If $hOpenFile = -1 Then
    SetError( 1 )
    Return 0
  EndIf

  $hWriteFile = FileWriteLine( $hOpenFile, $sText )

  If $hWriteFile = -1 Then
    SetError( 2 )
    Return 0
  EndIf

  FileClose( $hOpenFile )
  Return 1
EndFunc
;==============================================
; Local Constant/Variable Declaration Section
;==============================================

$s_SmtpServer = "smtp.nnnnnnn.com"
$s_FromName = $CmdLine[1];1st command line parameter
$s_FromAddress = $CmdLine[2];2nd command line parameter
$s_ToAddress = $CmdLine[3];3rd command line parameter
$s_Subject = $CmdLine[4];4th command line parameter
$s_helo = "EHLO " & @ComputerName
$s_first = @CRLF
Dim $as_Body[2]
$as_Body[0] = $CmdLine[5];5th command line parameter
$as_Body[1] = @CRLF &  @CRLF &  @CRLF & "*** End of Message ***"

$response = _INetSmtpMail ($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body, $s_helo, $s_first)
$err = @error
If $Response = 1 Then
    _FileAppend ("\\cscdev1\logs$\MailSent.txt", "Email successfully sent to " & $s_ToAddress _
     & " with subject " & $s_Subject & " at " & @MDAY & "\" & @MON & "\" & @YEAR & " @" & @HOUR & ":" &  @MIN)
 Else
    _FileAppend ("\\cscdev1\logs$\MailError.txt", "Email not sent to " & $s_ToAddress _
     & " with subject " & $s_Subject & @CRLF & " Mail failed with error code " & $err & " at " & @MDAY & "\" & @MON & "\" & @YEAR & " @" & @HOUR & ":" &  @MIN) 
EndIf

Any help / input appreciated thanks people :-)

Edited by Ashaman
Link to comment
Share on other sites

  • 2 weeks later...

Hi,

I have the same problem. It seems like the compiled script is working, if you are doing an asynchronous call like with CreateProcess or _spawnl(_P_NO_WAIT, ...).

But still in some cases, the script won't execute even with CreateProcess(...). The process is started (the compiled.exe appears in the taskmanager) but doesn't execute and so it does not terminate.

Maybe, the compiled script needs the calling application to process it's messages. Can someone comfirm that?

If so, IMO, this should be subject to change.

Regards,

weigo

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...