Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sendkeys not working 1

Status
Not open for further replies.

snikde

Programmer
Mar 13, 2002
35
US
I need to run a command line for an application installed on my machine. First I need to change to the directory where the .exe is located and then execute the command. I thought I could start a cmd window and then use sendkeys to cd to the directory and then execute the command line. Sendkeys is simply to flaky, I even have wait states and still its not consistent. The space {Space} does not seem to work at all. Num Lock is off. No luck. Is there another way to send to command lines to a cmd window either in background or foreground using VB other than Sendkeys?

Thxs,
 
Have you looked into the possibility of using the Shell command to execute this program?
 
Not sure how to use just the Shell command, i.e. to hand in all the parameters I need to. I need to run the command line: ug_convert_part -mm -d n:\thisistheobject.prt -o c:\temp. This needs to be run from a particular program file dir as it has pathing issues with supporting .dll's.

Thxs
 
Not sure how to use just the Shell command, i.e. to hand in all the parameters I need to. I need to run the command line: ug_convert_part -mm -d n:\thisistheobject.prt -o c:\temp. This needs to be run from a particular program file dir as it has pathing issues with supporting .dll's.

Thxs
 
snikde,

Further to bjd4jc's

Try something like this;

Dim OrigDir$

OrigDir$=CurDir$

ChDrv PathRequired$
ChDir PathRequired$

Shell "ug_convert_part -mm -d n:\thisistheobject.prt -o c:\temp"

ChDrv OrigPath$
ChDir OrigPath$


regards Hugh

 
Hugh,

Great! The idea worked. One last thing, the command line I send would normally return to the command window the result of its action, i.e. Parts Converted 1, etc. etc. Is there any way to capture this message and return it to the VB user?

Thanks!
 
snikde,

You should be able to redirect the commands output to a text file with;

Shell "ug_convert_part -mm -d n:\thisistheobject.prt -o c:\temp > log.txt"

or if you want a historical log append it with;

Shell "ug_convert_part -mm -d n:\thisistheobject.prt -o c:\temp >> log.txt"

Then back in VB do;

dim f%, LogContents$

f=freefile
Open "log.txt" for input as f
LogContents = Input$(LOF(f), f)
close f

regards Hugh





 
Well, I am stcuk again. I have created a command in VB that yeilds the following output to the Immediate window.

"c:\Program Files\EDS\Unigraphics NX 2.0\UGII\ug_convert_part.exe" -in C:\Temp\3_1.prt -o C:\Temp\convert > c:\temp\log.txt

It will not work from within VB but if I cut and paste the debug output into a shell window it works just fine.

any thoughts?

I have the quotes in the command path because of the spaces but it does not work without them either.

 
snikde,

Hmmm! You probably have to nest the quotes and it can be tricky.

Have you tried;

Shell ""c:\Program Files\EDS\Unigraphics NX 2.0\UGII\ug_convert_part.exe" -in C:\Temp\3_1.prt -o C:\Temp\convert > c:\temp\log.txt"

or

Shell Chr$(34) & "c:\Program Files\EDS\Unigraphics NX 2.0\UGII\ug_convert_part.exe" & chr$(34) & " -in C:\Temp\3_1.prt -o C:\Temp\convert > c:\temp\log.txt"

regards Hugh
 
Hugh,


Tried the above and a few other options. Its weird that I cannot get it to run.

Guy
 
snikde, it won't work. You cannot use DOS IO redirection features using the Shell function. It is only supported on MS-DOS. However, you can use command.com or cmd.exe to run a console program using the Shell function and send its output to a text file.

See thread222-701371 for two possible solutions.
 
Or, of course, for this simple console stuff you can leverage the Windows Script Host:

Option Explicit

Private Sub Command1_Click()
Dim WshShell As Object
Dim oExec As Object
Dim strOutput As String

With CreateObject("WScript.Shell")
With .Exec("cmd /c dir c:\")
strOutput = ""
Do While .Status <> 1
strOutput = strOutput & .StdOut.ReadAll
DoEvents
Loop
End With
End With
Text1.Text = strOutput
Me.SetFocus
End Sub
 
snikde,

Sorry I assumed my previous redirection example had worked.
Hypetia's post prompted me to look at my own code for such stuff and sure enough it is all preceded with Environ$("COMSPEC") & " /C " &

Environ$("COMSPEC") should return the name of the default Command processor on the machine; typically Command.com or Cmd.exe. Use of Environ$ is generally frowned upon but in this case it has never failed me.

The answer could look something like;

Shell Environ$("COMSPEC") & " /C " & Chr$(34) & "c:\Program Files\EDS\Unigraphics NX 2.0\UGII\ug_convert_part.exe" & chr$(34) & " -in C:\Temp\3_1.prt -o C:\Temp\convert > c:\temp\log.txt"

Others I expect may have alternatives<g>.

regs Hugh
 
Gentlemen,

That did it! I think I am all set! Thanks for the nice finish to the week. I will sleep a little more peacefully this weekend.


Guy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top