Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Redirect CreateProcess output to another window
Message
De
02/10/2012 14:14:51
Emerson Reed
Folhamatic Tecnologia Em Sistemas
Americana - São Paulo, Brésil
 
 
À
20/09/2012 14:37:28
Emerson Reed
Folhamatic Tecnologia Em Sistemas
Americana - São Paulo, Brésil
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Versions des environnements
Visual FoxPro:
VFP 9
OS:
Windows 7
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01553333
Message ID:
01554153
Vues:
54
J'aime (1)
Hi Folks.
I finally got what I wanted! very big smile
I followed another path: use WSH (Windows Scripting Host) instead of CreateProcess API.

Here is the code:
* http://technet.microsoft.com/en-us/library/ee692837.aspx
* http://support.microsoft.com/kb/278411/en-us
* http://www.experts-exchange.com/Programming/Languages/C/Q_27717068.html
* http://blog.crankybit.com/redirecting-output-to-a-file-in-windows-batch-scripts/
* http://www.pg-forum.de/programmierung/4216-dump-ber-windowsscriptinghost.html

Clear

Local lcLogFile
m.lcLogFile = "C:\Temp\Log.txt"

Local lcCommand
m.lcCommand = [%comspec% /c ] + ;
   [""C:\Program files\PostgreSQL\9.2\bin\pg_dump.exe" ] + ;
   [--verbose ] + ;
   [--file="C:\Temp\efiscal_20121001_e9999.backup" ] + ;
   [--format=c --compress=9 --host localhost --port 5432 ] + ;
   [--username postgres --no-password --schema=e9999 efiscal"] + ;
   [ 1>] + m.lcLogFile + [ 2>&1]

Local loWSH As "WScript.Shell"
m.loWSH = Createobject("WScript.Shell")

Local lnReturn, lnAttempts, llFinished, lnHandle
m.lnAttempts = 0
m.lnReturn = m.loWSH.Run(m.lcCommand,0,.F.)
If m.lnReturn==0 && No error
   Do While Not m.llFinished
      If File(m.lcLogFile)
         * The file can't be opened for read/write while
         * command is still in progress...
         m.lnHandle = Fopen(m.lcLogFile,12)
         If m.lnHandle >= 0
            m.llFinished = .T.
            Fclose(m.lnHandle)
         Endif
         ? Filetostr(m.lcLogFile)
      Else
         apiSleep(10) && Wait...
         m.lnAttempts = m.lnAttempts + 1
         If m.lnAttempts==10
            m.llFinished = .T.
            m.lnReturn = -1
         Endif
      Endif
      DoEvents
   Enddo
   If File(m.lcLogFile)
      Delete File (m.lcLogFile) && Recycle
   Endif
Endif

If Not m.lnReturn==0 && An error occurred
   ? "Error ", m.lnReturn
Endif

m.loWSH = Null
Return

Function apiSleep
   Lparameters nMiliseconds
   Declare Integer Sleep In Win32API As apiSleep ;
      Integer nMiliseconds
   Return apiSleep(m.nMiliseconds)
Endfunc
Emerson Santon Reed
"One Developer CAN Make a Difference. A community CAN make a future." - Craig Boyd
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform