Welcome, Guest
Username: Password: Remember me
Qui si parla italiano
  • Page:
  • 1

TOPIC:

Esecuzione di un file .BAT con parametro da una applicazione VO 02 Mar 2023 23:40 #25514

  • claudiocarletta
  • claudiocarletta's Avatar
  • Topic Author


  • Posts: 94
  • Salve a tutti,
    per effettuare il salvataggio del database MySQL ho scritto un file SalvaDB.BAT con il parametro timestamp in maniera tale che il file .SQL creato sia riferito alla data e ora attuale.
    Eseguendo il file SalvaDB.BAT da riga di comando seguito da una serie di numeri per simulare il timestamp, funziona perfettamente.

    Questo è il file SalvaDB.BAT
    @echo off
    :: ---- SETUP ----
    :: db user name
    set dbuser=root
    :: db user password
    set dbpass=xxxxxxxxx
    :: db list (lista di DB separati da uno spazio)
    set dblist=apprendistato
    :: backup directory destinazione dump
    set bkupdir=C:\Apprendistato\Backup
    :: Cartella di installazione mysql
    set mysqldir=C:\Program Files\MySQL\MySQL Server 8.0
    :: Data di sistema
    set mydata=%1
    :: -----------------------------------------------------
    :: NON MODIFICATE SOTTO
    echo MySQLDump start >> log.txt
    for %%f in (%dblist%) do (
    echo backing up %%f ...
    "%mysqldir%\bin\mysqldump" --user=%dbuser% --password=%dbpass% --databases %%f --opt --quote-names --allow-keywords --events --routines --complete-insert --skip-lock-tables > "%bkupdir%\Apprendistato%mydata%.sql"
    echo OK! 
    echo backup di %%f OK! >> log.txt
    )
    echo MySQLDump Finito>> log.txt
    echo ----- >> log.txt
    echo Procedura terminata correttamente!

    Ho fatto il metodo:
    METHOD Salva( )
        LOCAL sNomeFile	AS STRING
        LOCAL sParam	AS STRING
        
        sNomeFile := "SalvaDB.bat"
        SetTimeSep(Asc("_"))
        sParam := DToS(Today()) + Time()
        SetTimeSep(Asc(":"))
        AttivaShellExecute(sNomeFile, sParam)
    RETURN NIL

    Ho provato con un metodo che ho riesumato da un vecchio programma ma non mi funziona
    METHOD AttivaShellExecute(sNomeFile as STRING, sParam as STRING) 
    	LOCAL ptrShEx			AS PTR				
    	LOCAL sShEx				AS STRING				
    	LOCAL lShEx := FALSE	AS LOGIC
    	
    	ptrShEx := ShellExecute(oApp:handle(), AsPsz("Open"), AsPsz(sNomeFile),  ;
    			  AsPsz(sParam), AsPsz(WorkDir()), SW_SHOWNORMAL)
    	DO CASE
    		CASE ptrShEx = 0	
    			sShEx := "The operating system is out of memory or resources."
    		CASE ptrShEx = ERROR_FILE_NOT_FOUND	
    			sShEx := "The specified file was not found."
    		CASE ptrShEx = ERROR_PATH_NOT_FOUND	
    			sShEx := "The specified path was not found."
    		CASE ptrShEx = ERROR_BAD_FORMAT	
    			sShEx := "The .EXE file is invalid (non-Win32 .EXE or error in .EXE image)."
    		CASE ptrShEx = SE_ERR_ACCESSDENIED	
    			sShEx := "The operating system denied access to the specified file."
    		CASE ptrShEx = SE_ERR_ASSOCINCOMPLETE	
    			sShEx := "The filename association is incomplete or invalid."
    		CASE ptrShEx = SE_ERR_DDEBUSY	
    			sShEx := "The DDE transaction could not be completed because other DDE transactions were being processed."
    		CASE ptrShEx = SE_ERR_DDEFAIL	
    			sShEx := "The DDE transaction failed."
    		CASE ptrShEx = SE_ERR_DDETIMEOUT	
    			sShEx := "The DDE transaction could not be completed because the request timed out."
    		CASE ptrShEx = SE_ERR_DLLNOTFOUND	
    			sShEx := "The specified dynamic-link library was not found."
    		CASE ptrShEx = SE_ERR_FNF	
    			sShEx := "The specified file was not found."
    		CASE ptrShEx = SE_ERR_NOASSOC	
    			sShEx := "There IS no application associated with the given filename extension."
    		CASE ptrShEx = SE_ERR_OOM	
    			sShEx := "There was not enough memory to complete the operation."
    		CASE ptrShEx = SE_ERR_PNF	
    			sShEx := "The specified path was not found."
    		CASE ptrShEx = SE_ERR_SHARE	
    			sShEx := "A sharing violation occurred."
    		OTHERWISE
    			lShEx := TRUE
      ENDCASE
      IF ! lShEx
      	InfoBox{SELF, "Elaborazione ShellExecute", sShEx}:Show()
      ENDIF
    RETURN NIL
    Il metodo viene eseguito senza alcun errore apparente. Il codice di ritorno ptrShEx è 42 ma sembra che non sia nella lista dei possibili errori.


    Qualcuno può aiutarmi?
    Grazie

    Please Log in or Create an account to join the conversation.

    Esecuzione di un file .BAT con parametro da una applicazione VO 03 Mar 2023 05:06 #25517

    • wriedmann
    • wriedmann's Avatar


  • Posts: 3366
  • Ciao Claudio,
    una cosa fondamentale: un file bat o cmd non è un eseguibile, e neanche un documento. Perciò ShellExecute non può eseguirlo.
    Un file bat o cmd è una sequenza di comandi che deve essere eseguito dall'interprete della riga di comandi.
    Se vuoi allora eseguire un file bat o cmd devi eseguire l'interprete della riga di comandi "cmd.exe" e passargli il file bat come parametro, e inoltre devi usare il parametro /c:
    cmd.exe /c SalvaDB.bat
    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    Esecuzione di un file .BAT con parametro da una applicazione VO 03 Mar 2023 06:56 #25519

    • claudiocarletta
    • claudiocarletta's Avatar
    • Topic Author


  • Posts: 94
  • Grazie Wolfgang,
    lo provo appena possibile e ti faccio sapere

    Sempre prezioso, grazie
    Claudio

    Please Log in or Create an account to join the conversation.

    Esecuzione di un file .BAT con parametro da una applicazione VO 03 Mar 2023 12:44 #25525

    • claudiocarletta
    • claudiocarletta's Avatar
    • Topic Author


  • Posts: 94
  • Ciao Wolfgang,
    ho provato e riprovato ShellExecute() con parametro e con stringa unica ma non ne vuole sapere di eseguirmi il .BAT
    METHOD Salva( )
        LOCAL sNomeFile	AS STRING
        LOCAL sParam	AS STRING
        
        sNomeFile := "cmd.exe"
        sParam := "/C SalvaDB.bat " + DToS(Today()) + StrTran(Time(), ":")
        AttivaShellExecute(sNomeFile, sParam)
    RETURN NIL
        
    METHOD AttivaShellExecute(sNomeFile as STRING, sParam as STRING) 
    	LOCAL ptrShEx			AS PTR				
    	LOCAL sShEx				AS STRING				
    	LOCAL lShEx := FALSE	AS LOGIC
    	
    	ptrShEx := ShellExecute(oApp:handle(), AsPsz("Open"), AsPsz(sNomeFile),  ;
    				AsPsz(sParam), AsPsz(WorkDir()), SW_SHOWNORMAL)
    	DO CASE
    		CASE ptrShEx = 0	

    e anche
    METHOD Salva( )
        LOCAL sNomeFile	AS STRING
        LOCAL sParam	AS STRING
        
        sNomeFile := "cmd.exe /C SalvaDB.bat " + DToS(Today()) + StrTran(Time(), ":")
        AttivaShellExecute(sNomeFile)
    RETURN NIL
        
    METHOD AttivaShellExecute(sNomeFile as STRING) 
    	LOCAL ptrShEx			AS PTR				
    	LOCAL sShEx				AS STRING				
    	LOCAL lShEx := FALSE	AS LOGIC
    	
    	ptrShEx := ShellExecute(oApp:handle(), AsPsz("Open"), AsPsz(sNomeFile),  ;
    				AsPsz(NULL), AsPsz(WorkDir()), SW_SHOWNORMAL)
    	DO CASE
    		CASE ptrShEx = 0	

    Hai qualche suggerimento da propormi?
    Claudio

    Please Log in or Create an account to join the conversation.

    Esecuzione di un file .BAT con parametro da una applicazione VO 03 Mar 2023 13:39 #25528

    • diobrando
    • diobrando's Avatar


  • Posts: 37
  • Ciao Claudio,
    hai provato a vedere il comando RUN di VO?

    Please Log in or Create an account to join the conversation.

    Esecuzione di un file .BAT con parametro da una applicazione VO 03 Mar 2023 14:17 #25529

    • wriedmann
    • wriedmann's Avatar


  • Posts: 3366
  • Ciao Claudio,
    purtroppo sono assente d'ora in poi.
    Guardo appena possibile e ti faccio sapere.
    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    Esecuzione di un file .BAT con parametro da una applicazione VO 03 Mar 2023 14:33 #25530

    • FFF
    • FFF's Avatar


  • Posts: 1420
  • Claudio,
    non vedo nessuna classe nelle intestazioni dei metodi - è davvero VO?
    Regards
    Karl (X# 2.16.0.5; Xide 2.16; W8.1/64 German)

    Please Log in or Create an account to join the conversation.

    Esecuzione di un file .BAT con parametro da una applicazione VO [Risolto] 03 Mar 2023 16:51 #25532

    • claudiocarletta
    • claudiocarletta's Avatar
    • Topic Author


  • Posts: 94
  • Ciao Stefano,
    avevo completamente dimenticato il vecchio RUN di Clipper e quindi di VO
    Funziona perfettamente.
    Ho usato <oApp>:Run(<cCommand>) ---> liReturnNum che mi ritorna anche l'eventuale errore
    Grazie a tutti

    Please Log in or Create an account to join the conversation.

    • Page:
    • 1
    Moderators: wriedmann