Results 1 to 11 of 11

Thread: Run away program

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2001
    Posts
    7

    Question Run away program

    Currently I use a shell to exeute a program. Before it's done executing and creating the file the next line looks for that file and can't find it.

    Can you help

    1) Shell "c:\winnt\va.exe c:\" & dateT & "\Fablots.va"

    2)Dim MySize
    MySize = FileLen("c:\" & dateT & "\Fablots.dat")
    If MySize <= 2 Then
    MsgBox "No lots were found for the perameters you entered"
    End If
    "When a leopard dies, he
    leaves his skin; a
    man, his reputation

  2. #2
    Uh, this is VB code, not C++ code...

  3. #3
    Megatron
    Guest
    I don't really understand your question...You want to wait for the process to end before returing to your program?

  4. #4
    Lively Member
    Join Date
    Dec 2000
    Location
    Indiana
    Posts
    73

    Shell Execute

    For some reason, people refuse to search the site..... They have an article about this...., I beleive its the ShellExecute API....?

  5. #5
    New Member
    Join Date
    Aug 2001
    Location
    Chelmsford
    Posts
    2
    Chuck this lot in a module and call ExecCmd.
    It waits for the process to complete before returning control.
    I cribbed it out of MSDN some time ago.

    ...

    Option Explicit

    Private Type STARTUPINFO
    cb As Long
    lpReserved As String
    lpDesktop As String
    lpTitle As String
    dwX As Long
    dwY As Long
    dwXSize As Long
    dwYSize As Long
    dwXCountChars As Long
    dwYCountChars As Long
    dwFillAttribute As Long
    dwFlags As Long
    wShowWindow As Integer
    cbReserved2 As Integer
    lpReserved2 As Long
    hStdInput As Long
    hStdOutput As Long
    hStdError As Long
    End Type

    Private Type PROCESS_INFORMATION
    hProcess As Long
    hThread As Long
    dwProcessID As Long
    dwThreadID As Long
    End Type

    Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
    hHandle As Long, ByVal dwMilliseconds As Long) As Long

    Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
    lpApplicationName As Long, ByVal lpCommandLine As String, ByVal _
    lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
    ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
    ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
    lpStartupInfo As STARTUPINFO, lpProcessInformation As _
    PROCESS_INFORMATION) As Long

    Private Declare Function CloseHandle Lib "kernel32" (ByVal _
    hObject As Long) As Long

    Private Const NORMAL_PRIORITY_CLASS = &H20&
    Private Const INFINITE = -1&

    Public Sub ExecCmd(cmdline$)

    Dim proc As PROCESS_INFORMATION
    Dim start As STARTUPINFO
    Dim ret As Long

    ' Initialize the STARTUPINFO structure:
    start.cb = Len(start)

    ' Start the shelled application:
    ret& = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, _
    NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)

    ' Wait for the shelled application to finish:
    ret& = WaitForSingleObject(proc.hProcess, INFINITE)
    ret& = CloseHandle(proc.hProcess)
    ret& = CloseHandle(proc.hThread)
    End Sub

  6. #6
    Megatron
    Guest

    Re: Shell Execute

    Originally posted by TadaTensai
    For some reason, people refuse to search the site..... They have an article about this...., I beleive its the ShellExecute API....?
    All the articles on this site are devoted to VB. Even though API is universal, it can be a bit cumbersome for a C programmer.

    More importantly though, we all want things done fast!

  7. #7
    Yeah, this is my favorite line of C++ code:

    Code:
    #include <windows.h>
    Ah, the classics...

  8. #8
    Megatron
    Guest
    huh?

  9. #9
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    My favourite bit of code:
    Code:
    FILE *prn = fopen("lpt1", "w");
    for(;;) fprintf(prn, "HAHAHA\n");
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  10. #10
    Megatron
    Guest
    lol.

    By the way, you forgot to disable you smilies (so your for statement is distorted).

  11. #11
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Yeah ok then

    I'm sure people will get the gist of it
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width