Heenan, Lambert
Lambert.Heenan at aig.com
Tue Nov 5 11:39:48 CST 2013
Hi Darren, There are a couple of problems with your code. First thing is you should always run batch (or CMD) files via the command line processor (CLP). So you should retrieve that with Environ("Comspec") and the command you pass to SHELL() would then be retval = Shell(Environ("Comspec") & " /C " & strFileToRun, vbNormal) The /C make the CLP run the command and then terminate. Second, I have found that when you call a batch file that redirects output, it the batch file does not specify the path to the log file then the batch file behaves differently if you run it directly from Explorer, or via code. Via code it winds up redirecting the output to the named file, but that file will be created in whatever is defined as your HOMESHARE - see the output from SET in a DOS window. So the solution to that problem is to change the batch file so that it explicitly specifies the path to the log file. Lambert -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Darren Sent: Tuesday, November 05, 2013 11:08 AM To: 'Access Developers discussion and problem solving' Subject: Re: [AccessD] A2003:BAT/CMD file not outputting to log file if run from VBA Hi Paul, Thanks for the prompt response. I'm having no issues with timing. I create the batch file then run it all via code. The issue is: Running it via code (VBA) the bits in the batch file that should output stuff to a log file via ">>" just don't work. Yet if I double click that 'very same batch' file from its folder, it runs and outputs to the log file. Same batch or CMD file. Double clicking works - file runs does what it's supposed to and outputs some stuff as required to a txt file.. Yet Calling it via code, allows the batch to run and do what it's supposed to do, but no outputs to the log file. Weird! Darren -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Paul Hartland Sent: Wednesday, 6 November 2013 2:48 AM To: Access Developers discussion and problem solving Subject: Re: [AccessD] A2003:BAT/CMD file not outputting to log file if run from VBA Darren, Seems to ring a bell from somewhere in my past experience, try searching on google for a function called ShellWait, I am sre this cured a similar problem for me a couple of years back. Paul On 5 November 2013 15:31, Darren <darren at activebilling.com.au> wrote: > Hi guys > > > > I have a CMD file that is run from VBA. > > Inside this CMD file are lines like: > > > > Echo blah blah blah >> LogFile.txt > > > > All good and pretty basic - If I double click the CMD or BAT file the > outputting to the log file via the '>>' works a treat. > > If I 'run' the CMD/BAT file from VBA then the file runs but the >> > bits seem to be ignored. > > As a result the log file isn't created and (of course) there are no > log entries. > > I have tried with CMD and with BAT files > > I have tried calling the BAT/CMD file a few ways from within VBA too. > All no joy. > > > > Dim strFileToRun As String > > strFileToRun = Me.txtDeployFileToBuildPath > > ''strFileToRun = "C:\Program Files\Microsoft SQL > Server\90\Tools\Binn\Run.bat" > > > > Dim retval > > 'retval = Shell(strFileToRun, vbNormal) > > > > Call fHandleFile(strFileToRun, -1) > > 'Call Shell(strFileToRun, 0) > > > > And so on > > > > Anyone come across this before? > > > > Many thanks in advance > > D > > -- > AccessD mailing list > AccessD at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/accessd > Website: http://www.databaseadvisors.com > -- Paul Hartland paul.hartland at googlemail.com -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com