Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / General / January 2005



Tip: Looking for answers? Try searching our database.

VB6 and Shell

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ed Wyche - 29 Jan 2005 22:39 GMT
This is the command I am using it is using other functions.

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 String, 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 String, _
     lpStartupInfo As STARTUPINFO, lpProcessInformation As _
     PROCESS_INFORMATION) As Long

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

  Private Declare Function GetExitCodeProcess Lib "kernel32" _
     (ByVal hProcess As Long, lpExitCode As Long) As Long

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

Public Function ExecCmd(cmdline$)
     Dim proc As PROCESS_INFORMATION
     Dim start As STARTUPINFO

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

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

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

retval = ExecCmd(App.Path & "\test.exe " & txtTestName.Text & ".cfg")

What it does it waits for this DOS command to finish before proceeding to
the next line.  What I want to to pipe the result to a text file so I can
read then later on.

Thanks
Ed
Norm Cook - 30 Jan 2005 13:14 GMT
Try this:
retval = ExecCmd(App.Path & "\test.exe " & txtTestName.Text & ".cfg >
x:\somepath\results.txt")

But note also that if txtTestName.Text contains spaces, you will need quotes
around it.
DOS views spaces as delimeters for command options.

> This is the command I am using it is using other functions.
>
[quoted text clipped - 73 lines]
> Thanks
> Ed
Ed Wyche - 30 Jan 2005 16:44 GMT
I tried that before and I see the DOS box flash and I check the directory
but there is no file in there.  Is there away to leave the DOS box open to
see if there is an error?

> Try this:
> retval = ExecCmd(App.Path & "\test.exe " & txtTestName.Text & ".cfg >
[quoted text clipped - 81 lines]
> > Thanks
> > Ed
mike - 30 Jan 2005 19:56 GMT
First thing I'd do is construct the argument to the ExecCmd
then use that string in the command.  That way, you can examine the
argument to make sure it's what you intended.
Second, I'd use the >> append operator to eliminate problems when the
destination file exists.
Can't tell for sure from your description, but if the shell command
actually worked before, the above may not teach you anything.

Third, I'd use VB to call a batch file that calls the command.
then you can use the pif file for the batch file to keep the window open
so you can see what's going on.

FWIW, my problem has always been the opposite.  Have to use
waitforsingleobject to FORCE VB to wait for completion of the external
program.
The shell command seems to run the external program asychronously as you
want.
mike

> I tried that before and I see the DOS box flash and I check the directory
> but there is no file in there.  Is there away to leave the DOS box open to
[quoted text clipped - 97 lines]
>>>Thanks
>>>Ed

Signature

Return address is VALID.
Wanted, PCMCIA SCSI Card for HP m820 CDRW.
FS 500MHz Tek DSOscilloscope TDS540 Make Offer
http://nm7u.tripod.com/homepage/te.html
Wanted, 12.1" LCD for Gateway Solo 5300. Samsung LT121SU-121
Bunch of stuff For Sale and Wanted at the link below.
http://www.geocities.com/SiliconValley/Monitor/4710/

Ed Wyche - 31 Jan 2005 05:17 GMT
I tried this.  I tried using the chr(34) around and I still can't get it.
It runs fine just as long as I don't put the > in there.

> First thing I'd do is construct the argument to the ExecCmd
> then use that string in the command.  That way, you can examine the
[quoted text clipped - 116 lines]
> >>>Thanks
> >>>Ed
Karl E. Peterson - 31 Jan 2005 20:18 GMT
What you need to do is invoke a secondary command processor.  There's simply no other
way to use redirection or pipes in a command line...

retval = ExecCmd(Environ("comspec") & " /k " & App.Path & "\test.exe " &
txtTestName.Text & ".cfg > x:\somepath\results.txt")

The /k will keep the window open.  When you have it working, change that to /c.
Signature

[Microsoft Basic: 1976-2001, RIP]

> I tried that before and I see the DOS box flash and I check the
> directory but there is no file in there.  Is there away to leave the
[quoted text clipped - 87 lines]
>>> Thanks
>>> Ed
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.