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

How to run DOS program in background effectively 3

Status
Not open for further replies.

AirCon

IS-IT--Management
Apr 5, 2003
860
ID
faq184-4377

I hope it works for all cases. Please let me know if it doesn't.

Thanks to: Jim Osieczonek (jimoo)
For encouraging me to make FAQ :)

Regards

-- AirCon --
 
Hi AirCon,


First let me say Nice!. Wish you come out with more FAQs of the tricky ones you have solved. I like the act of Jim who encouraged you as well. Good work and compliments in fact to both.


Now on this specific one,
Your code.. Function GetCommander(tlFilename) contains
GETENV('WinDir') for locating the cmd.exe or Command.com.

In my system it is in System32 directory where as WinDir is C:\Windows

But still your code will work, because the system32 directory is in OS path.

What you are looking for is cmd.exe or command.com which could work without path specified as well. But adding the path is good work and safe.

You can code the whole thing in few lines, I feel. May be I am wrong, because I cannot at this moment test in multiple OS. But I feel this should work.

The few lines is.....
********************************
lcCmd = GETENV("ComSpec") + " /C " ;
+ "ping localhost > test.txt" && my Command line
loShell = CREATEOBJECT("wscript.shell")
lnSuccess = loShell.Run(lcCmd,1,.t.)
*********************************
** To view above in NotePad
lcCmd = "NotePad.exe test.txt"
lnSuccess = loShell.Run(lcCmd,1,.t.)
*********************************

But you need Windows Scripting with my code where ShellExecute or RUN command dosen't need that.


I do not want my comments to be a damper on your FAQs. I am honest in that. Some one else could come out with something else.

If you wish, you can provide this alternative also in your FAQ. But test those threee lines of code first. These are off my head.

(There are many ways to feed the Fox!)

:)

____________________________________________
Ramani - (Subramanian.G) :)
When you ask VFP questions, please add VFP version.
 
Hi Ramani,
Thanks for your compliments :)

Now let's discuss this.

In my system it is in System32 directory where as WinDir is C:\Windows
But still your code will work, because the system32 directory is in OS path.

What you are looking for is cmd.exe or command.com which could work without path specified as well. But adding the path is good work and safe.


Maybe you misunderstood the real purpose of this FAQ. Or am I picked the wrong title? It took more than 3 hours for me to made it (almost 1 hour just for the title [blush] )

The real purpose is, to execute a DOS program (no windows and nowait) and continue our program while the DOS program is running in background. This is where the problems begin and DOS commander have to get involved. If we need to wait, just use "RUN DosApps.exe" will do. there is no need to call DOS commander.

Yes you are right. Call the cmd.exe or command.com will worked. But why I provided the function is to make it works for any configuration. I don't want to get risk that it doesn't work for some *weird* configuration (I believe there are not many :) ). So it is provided to get the proper commander for each OS.

For Win9X/ME, probably there will no problem because the system only have one commander (command.com). But for NT based, both cmd.exe (32bit) and command.com (compatibility mode, 16bit) are exists. That's why the function checked for cmd.exe first. I can't use COMSPEC, because some people (who works on NT) sometimes changed it to use command.com instead of cmd.exe (I did it to make a 16bit apps). So I have to make sure that VFP is running the 32bit version of DOS commander.

There are other reason why I used the function just to get the commander, e.g. Dual (or more) boot. Again, I don't want to risk that the function will fail, under any configuration (well, I hope).

Now for the purpose I have mentioned, I can't use "loShell.Run(lcCmd,1,.t.)". But I put it for the third example with "loShell.Run(lcCmd,0,.f.)"

Finally, Thank you for the correction. The FAQ has been updated, hope it works now (for real :) ).
I should have tested the function first before submitted [blush]. I didn't test the function on NT based because my 2K got infected with a worm virus since two weeks ago (grr.. too lazy to fix/reinstall it). I forgot that DOS commander for NT based is under system32 directory (not in windir, DUHH!). The function will fail to get the correct one. Now I used COMSPEC but only to get to the right path.

To Slighthaze
I just saw one of your FAQ ( faq184-4259 ). Looks like it has the same purpose with mine. I didn't mean anything to your faq. If it is the same with my faq, please accept my apology. And I will delete mine.


Thanks and best regards

-- AirCon --
 
Hi Aircon,

You are spending so much time to share your code is appreciable.

Dont take it so hard on you. Make the FAQ as you want to express and the corrections (if at all necessary) can be
done easily in FAQs.

Some understandable expression is enough and the 'code' or the 'substance' is more important.

Next time, if you need any help to post a FAQ, (if you need any) you can contact me. But I dont think you need any, because I find your first FAQ normal and your forum posts are fine. FAQs are not different either.
** A suitable heading and
** a line or two of text to explain what you are doing
** and the code with text as comment -
** to explain what you do
** no need for grammer or flow of language..
** will fix the FAQ as shown 'here' now.
Your tricky solutions are more important.

Just read the following.. how many mistakes.. but human mind can read it..
*******************************************
"Aoccdrnig to rscheearch at Txes M&A Uinervtisy, it deosn't mttaer in waht oredr the ltteers in a wrod are, the olny iprmoetnt tihng is taht the frist and lsat ltteer be in the rghit pclae. The rset cab be a total mses and you can sitll read it wouthit a porbelm. Tihs is bcuseae the huamn mnid deos not raed ervey lteter by istlef, but the wrod as a wlohe."
*******************************************

And now My star to you. :)


____________________________________________
Ramani - (Subramanian.G) :)
When you ask VFP questions, please add VFP version.
 
Hi Jim and Ramani
Thanks to both of you. I really appreciate that :)

Ramani,
I get what mean. I'll remember that for the next time.

Wish you come out with more FAQs of the tricky ones you have solved

Can you tell me which one is that ?

BTW, should I contact slighthaze in private about this faq. But how could I contact him ?

Best regards

-- AirCon --
 
AirCon

BTW, should I contact slighthaze in private about this faq. But how could I contact him ?

If you go to faq184-4259 (the bottom of it) there is a place where you can send a comment to SlightHaze about his FAQ.


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Mike,

Duhh. I thought it was just to send a comment in this forum. Thanks for telling me

Regards

-- AirCon --
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top