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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run a DOS Program with a VARIBABLE Parameter ???? 2

Status
Not open for further replies.

kev100

Programmer
Jun 20, 2006
28
US
I'm thinking that is cannot be very complicated...but I can't find a solution anywhwere.

I'm running a VFP 7.0 .prg's

I need to run an external a non-vfp program using a VFP value as a parameter.

Currently, I have tried the RUN command:

Run c:\programs\Prog1.exe

This causes the program to run in a pop-up Window just fine.

However, I need to run the program with the parameter:

Run c:\programs\Prog1.exe <phone number>

The customer's phone number is 8645551234

The phone number is stored in a VFP .dbf table in the TEL field.

When I try the command:

RUN c:\programs\Prog1.exe TEL

...it will run Prog1.exe using, literally "TEL" as the parameter...not the customer's phone number.

I need it to run the program as:

RUN c:\programs\Prog1.exe 8655551234

Does anyone know of a way to pass the value stored in TEL as a parameter in a RUN command??

Any advice GREATLY appreciated.

Thanks
 
Dave,

Thanks very much.

I gave that a try and the pop-up command window will briefly flash...but then close.

It is evidently hitting some sort of error, but it's too quick to tell.

I'm not sure if it's something with the STORE / RUN process, or if I've got the syntax wrong, the external program itself, or other.

To test...I tried the following:

Run C:\WINDOWS\system32\calc.exe

...this ran the little Windows pop-up calculator just fine.


Run c:\programs\Prog1.exe TEL

...this ran the Prog1.exe just fine (but using TEL literally)


Then:

STORE "C:\WINDOWS\system32\calc.exe" to cCommand
RUN (cCommand)

...this resulted in just that quick command window flash, but did not run the program

Nor did
STORE "C:\programs\Prog1.exe tel" to cCommand
RUN (cCommand)

....which produced the same window-flash.

Am I mis-typing anything with the STORE / RUN option? I was hope that it would work (just as a verification test) with the calc.exe program.

Thanks...
 
In an early part of your project place the ShellExecute declaration below. Then wherever needed call a custom function such as I have here named ShellExec() but you can name the subroutine however you wish. The parameters are set to spin off another independent application.
Code:
DECLARE INTEGER ShellExecute IN Shell32.DLL ;
		INTEGER nWinHandle,;
		STRING cOperation,;   
		STRING cFileName,;
		STRING cParameters,;
		STRING cDirectory,;
		INTEGER nShowWindow

*********
PROCEDURE ShellExec (exeName, exeParms, exePath)
LOCAL nStat, errorDesc
nStat = ShellExecute(0,"open",exeName,exeParms,exePath,1)
* If nStat > 32, then it is the Instance Handle
* To get a Windows Handle see support.microsoft.com/kb/q242308/
IF nStat <= 32
	errorDesc = ICASE(nStat=2,"Invalid path or filename", ;
					nStat=8,"Insufficient memory", ;
					nStat=11,"invalid EXE file", ;
					nStat=31,"Invalid action, or no application associated with the specified file", ;
					"Error description not available")
	MESSAGEBOX("Error "+LTRIM(STR(nStat))+" ... "+errorDesc,16,"Program did not start.",2000)
ENDIF
RETURN
 
Using the above routine I can call an old dBase DOS application (using command.com on a Win2000/XP) using this code. Other destination applications may expect other parameter structures.

? ShellExecute(0,"open","command.com","","C:\Windows\system32",1)
(I'm not sure what goes in the 4th slot for "parameter".)

? ShellExecute(0,"open","myApp.exe","[PASS TEXT HERE]","\\myServer\myFolder",1)
 
Or to modify DSummZZZ's solution:

STORE "c:\programs\Prog1.exe " + TEL to cCommand
RUN &cCommand

This is how I would modify it to text to my DOS dBase application:

STORE "c:\programs\Prog1.exe [" + TEL + "]" to cCommand
RUN &cCommand
 
dbMark,

Thanks very much.....

In my current situation...I have to call small .prg programs as needed. This is actually a larger packaged visual-type program which is written in VFP. We have the option to add "command buttons" which can be tied to .prg's

When the user clicks the button, it will do whatever is specified in that button's properites (kinda like PowerPoint or MS Access).

I'm not on-site right now...so I cannot do any tests...but....
Can/should the first of your options be run, in its entirety, every time the function is needed?

Or...is the 2nd and/or 3rd options the best to use, since I can only run a .prg with all the code everytime the function is needed?

In other words....I don't think there's a place in this packaged program to run a section of custom code once at startup...so...if the first option is necessary...can all of it be run every time the "Prog1.exe tel" is needed?

Thanks
 
The following code is used in one of my project.
It uses Windows Script Host (which needs to be installed) but it offers an option to hold execution of your program.

Code:
oWSH = CREATEOBJECT("wscript.shell")
oWSH.Run(lcProgram + " " + lcParams, lnWindowState, lnSuspend)
  && lcProgram: Full path of application to run
  && lcParams: Additional parameters
  && lnWindowState: 0 (invisible)
  && lbSuspend: Suspend the current application, yes (.t.) or no (.f.)

For more on WSH:
A topic in the Automation forum pointed me towards WSH, but I can't seem to find that topic again.
 
Folks...

Thanks very much.

Adding the "&" did the trick.

The lines...

STORE "c:\programs\Prog1.exe " + TEL to cCommand
RUN &cCommand

...run that external app AND pass the VFP data as the parameter.

Beautiful !

One odd thing, though...and this is probably something about that particular app...

When is it run...it has its own pop-up style window which will disappear when the program is closed. But Behind it is that Dos-like command prompt window as well. It will close when that app is closed...but it just looks kinda odd.

Is this a common thing when calling an external program via a command line...or is it prob. something in this particular app?

Again....thanks VERY MUCH for that code...it made a huge difference.

Kev100
 
I looked closely at that cmd widow that pops up in the background.

I think it is some sort of error window. The error message is not a Windows-based one...but just a Dos-like line in a command window.

It reads (pharaphrased):

'[shows the path of the current main FoxPro app]'
CMD.EXE was run with the above path as the directory.
UNC paths are not allowed. Defaulting to Windows directory.

I tried to add a SET PATH command with those above 2 lines.
....but the same window pops up.

Also tried HIDE WINDOW "command"
But got the error message: "command" not defined

Thanks
 
UNC = Universal/Uniform Naming Convention and the format is \\server\volume\directory\file.

Have you tried using Drive letters?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top