Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Running system commands
Message
 
 
À
22/03/2007 10:44:04
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Divers
Thread ID:
01206831
Message ID:
01207083
Vues:
34
>Soooo..... what the heck do I do to get this working ?
>
>As I said previously It does work from within a .bat but I don't want to use that I'd like to keep the os call within the programs click event.
PROCEDURE RunShellScript
LPARAMETERS tcCommand, tlSilentMode, tcRetVal

IF EMPTY(m.tcCommand)
	RETURN
ENDIF

LOCAL oShell, llError, loException, lnErrorCode
llError = .F.
TRY
	oShell = CREATEOBJECT("WScript.Shell")
CATCH TO loException
	IF m.tlSilentMode
		tcRetVal = "Run-time error: WScript.Shell Object is not Found"
	ELSE
		=MESSAGEBOX("Run-time error: WScript.Shell Object is not Found")
	ENDIF
	llError = .T.
ENDTRY
IF m.llError <> .T.
	TRY
		lnErrorCode = oShell.RUN(m.tcCommand, 0,.T.) && SW_SHOW_HIDDEN 0,SW_SHOW_NORMAL 1,SW_SHOW_MINIMIZED 2,SW_SHOW_MAXIMIZED 3
		IF m.lnErrorCode <> 0
			tcRetVal = "Error in running shell command. Error Code: " + TRANSFORM(m.lnErrorCode)
		ENDIF
	CATCH TO loException
		IF m.tlSilentMode
			tcRetVal = "Run-time error: WScript.Shell: " + ;
				m.tcCommand + CHR(13) + CHR(10) + Log_Error(m.loException)
		ELSE
			=MESSAGEBOX("Run-time error: WScript.Shell: " + m.tcCommand)
		ENDIF
		llError = .T.
	ENDTRY
ENDIF
RELEASE oShell

RETURN !m.llError
Supply your command as a string with fullpath for your .exe and a text file. (use fullpath function to get a path, or curdir())
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform