Shell not working

AlexanderBB

Well-known Member
Joined
Jul 1, 2009
Messages
2,099
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
Am I doing it correctly ?

Code:
 x = Shell("D:\A-Sides\doit.bat", vbNormalFocus)
         
         'wait for bat to finish
         
         Application.Wait (Now + TimeValue("0:00:10"))

The wait is working but Doit.bat doesn't run. Is something else needed?
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
What is Doit.bat supposed to do?

The contents of doit.bat are

ffmpeg.exe -nostats -i "B:\1950\SheetMusic\Mel Torme - Bewitched.mp3" -filter_complex ebur128=peak=true -f null - >outputfile8.txt 2>&1

but does that matter? I've spent all morning looking for why SHELL doesn't work and it's odd.. it seems I have the correct syntax and I've tried with both a .bat and .exe file and neither do anything. Could you give an example of a Shell command that works for you?
Thanks.
 
Upvote 0
The contents of doit.bat are

ffmpeg.exe -nostats -i "B:\1950\SheetMusic\Mel Torme - Bewitched.mp3" -filter_complex ebur128=peak=true -f null - >outputfile8.txt 2>&1

but does that matter?
It might matter. I see you are redirecting output to a text file, but (since my DOS days are so far behind me) what is the 2>&1 doing?
 
Upvote 0
How do you know that shell is not working? I recommend a test

Code:
Sub ShellTest()
    Dim X
    Dim FName As String


    FName = "C:\WINDOWS\NOTEPAD.EXE"
    If ExistFile(FName) Then
        X = Shell(FName, vbNormalFocus)  'since everyone has notepad.exe, this should work
    Else
        MsgBox "File " & FName & " cannot be found"
    End If
    
    FName = "D:\A-Sides\doit.bat"
    If ExistFile(FName) Then
        X = Shell(FName, vbNormalFocus)
    Else
        MsgBox "File '" & FName & "' cannot be found"
    End If
End Sub   


''' True if file exists
Function ExistFile(ByVal FileMask As String) As Boolean


    Dim TestString As String


    ''' A Backslash can give a false indication
    Do While (Right(FileMask, 1) = "\")
        FileMask = Left(FileMask, Len(FileMask) - 1)
    Loop


    ''' A colon can do the same
    Do While (Right(FileMask, 1) = ":")
        FileMask = Left(FileMask, Len(FileMask) - 1)
    Loop


    If FileMask <> "" Then
        TestString = Dir$(FileMask)
        ExistFile = (TestString <> "")
    Else
        ExistFile = False
    End If
End Function
 
Upvote 0
Thanks very much for the help. I did have something wrong, and needed to add change directory instructions to the batch file.
It fooled me by working ok in Command Prompt and I wrongly assumed shelling to the batch there would give the same result.
And I should have put a Pause in to observe it working (or not).

Rick the '2>&1' is part of the redirection, without it the text file was empty. It's something to do with stdout and stderr but I've no idea what they are.
 
Upvote 0
It might matter. I see you are redirecting output to a text file, but (since my DOS days are so far behind me) what is the 2>&1 doing?

Now you are making me feel old since I'm a command line jockey from way back. 2>&1 is a way to redirect both stderr and stdout; but it is an OS/2 & WINNT (and later Win version) feature. It never existed under DOS. A neat site for all things redirection:

http://www.robvanderwoude.com/redirection.php

http://www.robvanderwoude.com/battech_redirection.php
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top