Announcement

Collapse
No announcement yet.

ShellExecute does not send $CrLf 's

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • ShellExecute does not send $CrLf 's

    I can't seem to send a text string with $CrLf's embedded. In Body$ below, Eudora shows Test Test instead of two separate lines. Do I need to send something else other than $CrLf 's?

    Code:
    '
    Sub W_Email_Tape        
     common_Locals
      Local ppr As  String Pointer                 
      Local subj, body As String
    
      'find name only
      i = InStr(-1, Prm.Current_File_Name, "\") + 1
       subj$ = Mid$(Prm.Current_File_Name, i)  
         subj$ = Trim$(subj$)
    '     
       Body$ = "test " & $CrLf & $CrLf & "test" '  Tape_to_String
       
      s$ = "[EMAIL="gosta"]MailTo:gosta[/EMAIL]" & _
           "?Subject=" & subj$ & _
            "&Body=" & Body$ & _
           Chr$(0)
      ppr = StrPtr(s$)
    '>>>>>> Does not send $crlf's in Body$ or Eudora does not receive them.
      ShellExecute 0, "open", ByVal ppr, ByVal 0&, ByVal 0&, %SW_SHOWNORMAL 
    'HINSTANCE ShellExecute(
    '
    '    HWND hwnd, // Handle To Parent Window
    '    LPCTSTR lpOperation, // Pointer To String that specifies operation To perform
    '    LPCTSTR lpFile, // Pointer To filename Or folder Name String
    '    LPCTSTR lpParameters, // Pointer To String that specifies executable-file parameters 
    '    LPCTSTR lpDirectory, // Pointer To String that specifies Default directory
    '    Int nShowCmd  // whether file Is shown when opened
       
      
    '  ? Body$,, FuncName$
    End Sub
    '
    =====================================
    If a man could have half his Wishes,
    he would double his troubles.
    Ben Franklin
    =====================================
    It's a pretty day. I hope you enjoy it.

    Gösta

    JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
    LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

  • #2
    Nix request. Found the answer here: http://www.ianr.unl.edu/internet/mailto.html

    just had to
    Code:
         Replace $CrLf With "%0a" In Body$
    =======================================
    If you think you can win, you can win.
    Faith is necessary to victory.
    William Hazlitt (1778 - 1830)
    =======================================
    It's a pretty day. I hope you enjoy it.

    Gösta

    JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
    LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

    Comment


    • #3
      There appears to be a limit of about 2,000 characters that can be sent with shellExecute
      Code:
      '
      Sub W_Email_Tape        
       common_Locals
        Local ppr As  String Pointer                 
        Local subj, body As String
        'find name only
       
        i = InStr(-1, Prm.Current_File_Name, "\") + 1
         subj$ = Mid$(Prm.Current_File_Name, i)  
           subj$ = Trim$(subj$)
      '              
         Body$ = Tape_to_String 
         Replace $CrLf With "%0a " In Body$                             
      em20:   
        ln = Len(Body$)
         If ln > 2000 Then
           ?"The detailed Tape is too long to send from here." & $CrLf  & $CrLf & _
            "  Try just sending the totals and summary,"& $CrLf & _
            "and Attaching the file saved as '.Txt' from ." &  _
            "your email client." _
            ,%top, $Title
           Exit Sub 
         End If
       
       '2529 in orig too long?
      '  n = 2000             
      '   Body$ = Left$(body$, n) 
      '   Subj$ = Using$("   used #, of #, ", Len(Body$), ln)
        s$ = "MailTo:" & _
             "?Subject=" & subj$ & _
              "&Body=" & Body$ & _
             Chr$(0)
        ppr = StrPtr(s$)
        ShellExecute 0, "open", ByVal ppr, ByVal 0&, ByVal 0&, %SW_SHOWNORMAL 
       
      End Sub
      '
      Or am I doing something wrong here? When Body$ is something over 2,000 chars, it just doesn't execute. I tried any number of things, thinking it may have been a particular char sequence but that doesn't seem to be it. Anybody got any ideas? (Well I know some do but I mean about a char limit on ShellExecute.)


      ======================================
      "The secret of success is
      to know something nobody else knows."
      Aristotle Onassis (1906-1975)
      ======================================
      Last edited by Gösta H. Lovgren-2; 26 Sep 2009, 10:38 AM.
      It's a pretty day. I hope you enjoy it.

      Gösta

      JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
      LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

      Comment


      • #4
        Does this get around the limit for you?

        Code:
        #COMPILE EXE  'WaitShell.bas using CreateProcess
        #DIM ALL
        #INCLUDE "win32api.inc"
        FUNCTION PBMAIN () AS LONG
          
          LOCAL Milliseconds_To_Wait AS LONG
          Milliseconds_To_Wait = 2000   'use 0 for no wait
           WaitShell "NOTEPAD.EXE",Milliseconds_To_Wait
           ? "Waited" + STR$(Milliseconds_To_Wait) + " miliseconds, you can use 0 for no wait"
           
        END FUNCTION
        FUNCTION WaitShell(BYVAL CmdLine AS STRING, TimeOutInMilliseconds AS LONG) AS LONG
          'Shells to another process  with optional wait.  Use %INFINITE to wait until done
          LOCAL Si        AS STARTUPINFO
          LOCAL Pi        AS PROCESS_INFORMATION
          LOCAL Pid       AS DWORD
          Si.cb = SIZEOF(Si)
          Si.dwFlags = %STARTF_USESHOWWINDOW
          Si.wShowWindow = %SW_SHOWNORMAL
          Pid = CreateProcess("", _
                         BYVAL STRPTR(CmdLine), _
                         BYVAL %NULL, _
                         BYVAL %NULL, _
                         0, _
                         %NORMAL_PRIORITY_CLASS, _
                         BYVAL %NULL, _
                         BYVAL %NULL, _
                         Si, _
                         Pi)
          IF Pid THEN
            'Call WaitForInputIdle(pi.hProcess, %IGNORE)       'not needed
             FUNCTION =  WaitForSingleObject(pi.hProcess, TimeOutInMilliseconds)
             CALL CloseHandle(pi.hProcess)
             CALL CloseHandle(pi.hThread)
           ELSE
              ? "Unable to CreateProcess, error" + STR$(GetLastError)
           END IF
        END FUNCTION

        Comment


        • #5
          Originally posted by Mike Doty View Post
          Does this get around the limit for you?
          No it didn't Mike. Unless I tried it wrong (a quite real possibility).
          Code:
            '
          Sub W_Email_Tape        
           common_Locals
            Local ppr As  String Pointer                 
            Local subj, body As String
            'find name only
           
            i = InStr(-1, Prm.Current_File_Name, "\") + 1
             subj$ = Mid$(Prm.Current_File_Name, i)  
               subj$ = Trim$(subj$)
          '              
             Body$ = Tape_to_String 
             Replace $CrLf With "%0a " In Body$                             
           
            s$ = "MailTo:" & _
                 "?Subject=" & subj$ & _
                  "&Body=" & Body$ & _
                 Chr$(0)
           
          '  ppr = StrPtr(s$)
          '  ShellExecute 0, "open", ByVal ppr, ByVal 0&, ByVal 0&, %SW_SHOWNORMAL 
           
             w_WaitShell(s$, 200)'<<<<<< Here's call I tried
           
          End Sub
          '
          Yields an "Unable to create process" msg.

          =======================================
          "There are some people who would never
          have fallen in love
          if they had not heard
          that there was such a thing."
          François VI,
          duke de La Rochefoucauld,(1613)
          =======================================
          Last edited by Gösta H. Lovgren-2; 26 Sep 2009, 07:56 PM.
          It's a pretty day. I hope you enjoy it.

          Gösta

          JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
          LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

          Comment


          • #6
            I've passed over 32,000 characters using this:

            Code:
            FUNCTION PBMAIN AS LONG
              LOCAL Milliseconds_To_Wait AS LONG
              LOCAL Something AS STRING
              Something = STRING$(32000,"X")
              Milliseconds_To_Wait = 2000   'use 0 for no wait
              WaitShell "TEST1.EXE " + Something$,Milliseconds_To_Wait
            END FUNCTION
            FUNCTION WaitShell(BYVAL CmdLine AS STRING, TimeOutInMilliseconds AS LONG) AS LONG
              'Shells to another process  with optional wait.  Use %INFINITE to wait until done
              LOCAL Si        AS STARTUPINFO
              LOCAL Pi        AS PROCESS_INFORMATION
              LOCAL Pid       AS DWORD
              Si.cb = SIZEOF(Si)
              Si.dwFlags = %STARTF_USESHOWWINDOW
              Si.wShowWindow = %SW_SHOWNORMAL
              Pid = CreateProcess("", _
                             BYVAL STRPTR(CmdLine), _
                             BYVAL %NULL, _
                             BYVAL %NULL, _
                             0, _
                             %NORMAL_PRIORITY_CLASS, _
                             BYVAL %NULL, _
                             BYVAL %NULL, _
                             Si, _
                             Pi)
              IF Pid THEN
                'Call WaitForInputIdle(pi.hProcess, %IGNORE)       'not needed
                 FUNCTION =  WaitForSingleObject(pi.hProcess, TimeOutInMilliseconds)
                 CALL CloseHandle(pi.hProcess)
                 CALL CloseHandle(pi.hThread)
               ELSE
                  ? "Unable to CreateProcess, error" + STR$(GetLastError)
               END IF
            END FUNCTION
            
             
             
             
             
            REM TEST1.EXE
            FUNCTION PBMAIN () AS LONG
                 LOCAL s AS STRING
                 s = COMMAND$
                 ? "The length of s" + STR$(LEN(s))
            END FUNCTION

            Comment


            • #7
              Passing CHR$("MIKE",0,0,"DOTY") only receives 4 characters.
              Change to CHR$("MIKE",1,1"DOTY") and it receives all 10 characters.

              WaitShell "TEST1.EXE " + REPEAT$(10000,$CRLF), 0
              TEST1.EXE displays 20000
              Last edited by Mike Doty; 26 Sep 2009, 08:27 PM.

              Comment


              • #8
                Originally posted by Mike Doty View Post
                I've passed over 32,000 characters using this:
                I don't doubt it Mike. If I'm not using Wait_Shell wrong (see above snippet), the 2,000 bytes may be an inherent limitation in the "Mailtto:" function.

                I tried WaitShell with a small msg but it failed as well so either I'm using it wrong or WS won't execute the MailTo cmd.

                Thanks your trying.

                ===================================
                "It was the experience of mystery -
                even if mixed with fear -
                that engendered religion."
                Albert Einstein (1879-1955)
                ===================================
                It's a pretty day. I hope you enjoy it.

                Gösta

                JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
                LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

                Comment


                • #9
                  Try it with ShellExecuteEx and a separate parameter string (SEI.LpParameters) as shown here:
                  Win 32: Monitor Process with ShellExecuteEx June 22, 2001

                  Sorry that's so old, but hey, it still works.
                  Michael Mattias
                  Tal Systems (retired)
                  Port Washington WI USA
                  [email protected]
                  http://www.talsystems.com

                  Comment


                  • #10
                    Thx, Mike. I'll check it out later today or tonight for sure. Mother calls right now.

                    ==================
                    Be civil to all;
                    sociable to many;
                    familiar with few.
                    Ben Franklin
                    ==================
                    It's a pretty day. I hope you enjoy it.

                    Gösta

                    JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
                    LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

                    Comment


                    • #11
                      Mike (M), I tried your ShellExe this morning but couldn't get it to work for me. Here's the code
                      Code:
                      Function W_Email_Tape_MCM() As Long 'z_mcm_DoTheShellEx () As Long
                         Local SEI As ShellExecuteInfo, Stat As Long, E As Long
                       
                         Local hWaitProcess As Long
                         Local lpVerb As Asciiz * 20, lpParameters As Asciiz * 20, lpDirectory As Asciiz * 20, lpFile As Asciiz * %MAX_PATH
                         Local TimeOut2 As Long   ' "timeout" is another un-hilited "reserved" word which is truly only reserved
                                                  '  in the context of a TCP or UDP verb and can only be found with "search."
                                                  '  The error message if you use 'timeout' as a variable name is
                                                  '  "statement expected," which is a useless error message.
                      '
                      ' *******************************************************
                      ' My stuff
                       common_Locals
                      '  Local ppr As  String Pointer                 
                        Local subj, body As String
                        'find name only
                       
                        i = InStr(-1, Prm.Current_File_Name, "\") + 1
                         subj$ = Mid$(Prm.Current_File_Name, i)  
                           subj$ = $Title & " - " & Trim$(subj$)
                      '              
                         Body$ = Tape_to_String 
                         Replace $CrLf With "%0a " In Body$                             
                        s$ = "MailTo:" & _
                             "?Subject=" & subj$ & _
                              "&Body=" & Body$ & _
                             Chr$(0)
                         ? s$, %top, "body" 'shows fine
                                    lpVerb = "Open"
                      '              lpParameters   = ""
                                    lpFile = s$ '"C:\TestShExec.txt"
                                    Timeout2 = 30 * 1000            ' 30 secs
                      '
                      ' *******************************************************
                      '
                       
                       
                      '   Select Case ControlId
                      '          Case %IDC_OPEN_DOCUMENT
                      '              lpVerb = "Open"
                      '              lpParameters   = ""
                      '              lpFile = "C:\TestShExec.txt"
                      '              Timeout2 = 30 * 1000            ' 30 secs
                      '           Case %IDC_PRINT_DOCUMENT
                      '              lpVerb = "PRINT"
                      '              lpFile = "C:\TestShExec.txt"
                      '              lpParameters = ""
                      '              Timeout2 = 60 * 1000            ' 60 secs
                      '           Case  %IDC_OPEN_PROGRAM
                      '             'Windows Program
                      '             lpVerb = "Open"
                      '             lpFile = "notepad.exe"
                      '            lpParameters = "C:\TestShExec.txt"
                      '             ' DOS PROGRAM
                      '             lpFile ="C:\Software_Development\Pb-Dos\Exe\horse.exe"
                      '             lpParameters = ""
                      '             Timeout2 = 30 * 1000            ' 30 secs
                      '   End Select
                      '
                         SEI.cbSize       = SizeOf(SEI)
                         SEI.fmask        = %SEE_MASK_NOCLOSEPROCESS
                         SEI.hWnd         = hdlg 'hWnd
                         SEI.lpVerb       = VarPtr(lpVerb)
                         SEI.LpFile       = VarPtr(lpFile)
                         SEI.lpParameters = VarPtr (lpParameters)
                         SEI.lpDirectory  = %Null
                         SEI.nShow        = %SW_SHOW      ' should be zero for a document file PER MSDN DOC.
                                                          ' MSDN DOC IS WRONG, use SW_SHOW!
                         SEI.hInstApp     = 0             ' updated by function
                         SEI.lpIdList     = %Null         ' here down to hprocess ignored unless appropriate mask included in fmask
                         SEI.lpClass      = %Null
                         SEI.hkeyClass    = %Null
                         SEI.dwHotKey     = %Null
                         SEI.Item         = %Null
                         SEI.hProcess     = 0             ' will be updated by ShellExecuteEx
                         If IsTrue ShellExecuteEx(SEI) Then       ' function succeeded and returned
                              hWaitProcess = SEI.hProcess
                              Stat = WaitForSingleObjectEx (hWaitProcess, Timeout2, 0)
                      'No different        Sleep 10000 '10 secs
                              Select Case Stat
                                    Case -1&
                                         E = GetLastError
                      'gives Invalid Handle error 6                   MsgBox "Wait Failed:" & SystemErrorMessageText (E)
                                    Case %WAIT_OBJECT_0
                                         MsgBox "Wait returned from " & lpVerb & " on process completion"
                                    Case %WAIT_TIMEOUT
                                         MsgBox "Wait returned from " & lpVerb & " on Timeout"
                                    Case Else
                                         MsgBox "Unexpected Return, code=" & Str$(Stat)
                              End Select
                              CloseHandle hWaitProcess
                        Else
                            E = GetLastError
                            MsgBox "ShellExecuteEx failed:" & Str$(e) ' SystemErrorMessageText(E)
                        End If
                       
                      End Function '/mcm
                      '
                      I get an Invalid handle error. I suspect because I used hdlg (a global). The function succeeds though, in that it launches the MailtTo but some of the Body of the message is truncated. which doesn't happen with ShellExecute:
                      Code:
                      Sub W_Email_Tape '_NotUsed        
                       common_Locals
                        Local ppr As  String Pointer                 
                        Local subj, body As String
                        'find name only
                       
                        i = InStr(-1, Prm.Current_File_Name, "\") + 1
                         subj$ = Mid$(Prm.Current_File_Name, i)  
                           subj$ = $Title & " - " & Trim$(subj$)
                      '              
                         Body$ = Tape_to_String 
                         Replace $CrLf With "%0a " In Body$                             
                      '   Body$ = Right$(Body$, 2012)
                      em20:   
                        ln = Len(Body$)
                         If ln > 2000 Then
                           ?"The detailed Tape is too long to send from here." & $CrLf  & $CrLf & _
                            "  Try just sending the totals and summary (File Stuff>E),"& $CrLf & _
                            "and Attaching the file saved as '.Txt' from ." &  _
                            "your email client." _
                            ,%top, $Title
                           Exit Sub 
                         End If
                       
                       '2529 in orig too long?
                      '  n = 2000             
                      '   Body$ = Left$(body$, n) 
                      '   Subj$ = Using$("   used #, of #, ", Len(Body$), ln)
                        s$ = "MailTo:" & _
                             "?Subject=" & subj$ & _
                              "&Body=" & Body$ & _
                             Chr$(0)
                        ppr = StrPtr(s$)
                        ShellExecute 0, "open", ByVal ppr, ByVal 0&, ByVal 0&, %SW_SHOWNORMAL 
                      '  n = 5000
                      '   w_WaitShell(s$, n)
                       
                      End Sub
                      '
                      But won't send a long one.

                      The same Tape to send was used in each case.

                      ======================================================
                      "Men are not disturbed by things,
                      but the view they take of things."
                      Epictetus (55-135 A.D.)
                      "What about things like bullets?"
                      Herb Kimmel, Behavioralist, Professor of Psychology,
                      upon hearing the above quote (1981)
                      ======================================================
                      Last edited by Gösta H. Lovgren-2; 29 Sep 2009, 10:10 AM.
                      It's a pretty day. I hope you enjoy it.

                      Gösta

                      JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
                      LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

                      Comment

                      Working...
                      X
                      😀
                      🥰
                      🤢
                      😎
                      😡
                      👍
                      👎