Topic: Run external program from a script

Hello,

can anyone tell me if it is possible to run an external program from within a MVD script please. I would like to click a button and a MVD script would write a small text file to the hard drive based on the contents of an edit box or memo field. The script would then run the external executable program which I will write. Its purpose will be to process the little text file and write data to the serial or USB port to control an external hardware device.
Thanks in advance, David.

Re: Run external program from a script

If I am understanding you correctly, here is a snippet of code to do what you are looking to do:

procedure Form1_Button1_OnClick (Sender: string; var Cancel: boolean);
begin
     Form1.Memo1.Lines.SaveToFile('c:\text.txt');        //Memo1 would be your edit box or memo field
     OpenFile('c:\Program Files\YourProgram.exe');    //Run your program
end;

Re: Run external program from a script

Hello ehwagner,
You understood perfectly and it works great. Thank you for your help, David.

Re: Run external program from a script

Hello,
My MVD application runs an external proram using

OpenFile('myProg.exe');

and that works fine. However, I need to add command line text to the startup of this external file. For example, I would type
myProg.exe "mytext" if I was running it from the Windows command line either with or without the speech marks around the text.
I've tried various things but can't get this to work using the OpenFile command in a MVD script so can anybody help please.
Thanks, David

Re: Run external program from a script

Hi David,
Have you tried:
Openfile('myprog.exe','mytext');
That's the way you'd run something like like Notepad when specifying a particular file (see attached), so I'm guessing it might be the same in your case.
Derek.

Post's attachments

Attachment icon commandline.zip 334.85 kb, 455 downloads since 2019-01-07 

Re: Run external program from a script

Hello Derek,
Thanks but I tried that and many other things. The difference in my situation is that the command line isn't giving the name of a file that the external file needs to open (as in notebook opening a text file), I need to give the external program a parameter that it reads and uses that value in its program execution.
The external program is one I wrote myself to write the operating system into the SQLite data file. I can change the external program so it doesn't require the command line parameter but that would reduce some security and could add a bit of risk if the user runs it themselves without it being run from within the MVD script.
Regards, David

Re: Run external program from a script

Hello Derek,
I got it sorted. It needs to be written back to front as

OpenFile('myTextParameter','myExe.exe');

There will be a good reason for this beyond my simple understanding.
Thanks again for your help.
Regards, David