0

I am running Windows-7. I want to create a Windows Batch file which works like this:

  1. Run an exe with specified arguments. Wait for the complete execution of this exe. (This EXE is essentially recording an online video stream and is supposed to record it for 1 hour 5 minutes)
  2. If, however, exe exits (stops recording & exits execution) before the stipulated time period (1 hour 5 minutes), execute the same exe with different argument for the remaining duration. Kill the EXE execution when the total time period (including EXE's first tun in Step 1) reaches 1 hour 5 minutes.
  3. Continue to execute the exe with different argument till the cumulative time duration reached 1 hour 5 minutes.
  4. Kill the EXE execution and exit the batch file execution when the batch file has run for 1 hour 5 minutes.

Note: The exe takes two arguments: input stream address and the output filname. The only argument which changes in each run of the EXE above is the file name which changes from "FileName" in the first run to "FileName2" when the first run exits before 1 hour 5 minutes. And the filename is to be incremented to Filename2, Filename3 and so on till the cumulative run time of this batch file reaches 1 hour 5 minutes. For a real example, see this command:

"C:\Windows\System32\rtmpdump.exe" -i rtmpt://154.500.69.6/live -o "C:\Users\user\Desktop\Filename.extension"

The command mentioned above is what is to run the first time. In subsequent runs (which are necessitated only if this first execution exits before the goal of 1 hour 5 minutes), only the file name needs to be changed to Filename2.extension as shown in command below:

"C:\Windows\System32\rtmpdump.exe" -i rtmpt://154.500.69.6/live -o "C:\Users\user\Desktop\Filename2.extension"

And this sequence needs to continue till the cumulative run of this batch file reaches 1 hour 5 minutes.

4
  • 1
    PowerShell can for sure, Batch quite possibly too (even though I'm not a batch pro)
    – SimonS
    Jul 20, 2016 at 6:03
  • 1
    I don't see how batch can do this. Batch does not have a sophisticated way to know how much time has been progressed and act accordingly, though it may be able to program a scheduled task, but that may interfere with a succesfull recording. I would go for vbscript instead of batch, but if PowerShell can do it too, that is closer to batch.
    – LPChip
    Jul 20, 2016 at 6:35
  • 1
    @LPChip Batch could do this but it would be painful :)
    – DavidPostill
    Jul 20, 2016 at 12:37
  • Please note that Super User is not a script writing service. If you tell us what you have tried so far (including any scripts you are using) and where you are stuck then we can try to help with specific problems. You should also read How do I ask a good question?.
    – DavidPostill
    Jul 20, 2016 at 12:38

1 Answer 1

1

Batch cannot do this directly. All Batch usually does is run external programs. There is some capability to jump/goto/loop, and variables can be used, although using variables is kind of painful.

So, since most of what people do with Batch is to run external programs, your objective isn't going to be to learn Batch really well. Your objective will be to find a program that does the things you're wanting to do.

Running a program with command line parameters is doable. TASKLIST can help determine if a program is running, or WMIC. However, checking the time might not be the simplest thing.

Another option is to use Windows Scripting Host (WSH), which lets you run JScript (essentially JavaScript) or VBScript. This is done with the CScript program (or the WScript program). That approach will probably let you look at time, though details are more appropriately answered by StackOverflow (programming) rather than SuperUser (general computing).

(As noted elsewhere, PowerShell might also be a viable alternative that may be easier than Batch.)

Rather than checking if the recording lasted for 65 minutes, you might want to check the ERRORLEVEL (also known as the Error Code, Exit Code, or Return Code) of the program. Many programs use that as a way to easily communicate whether a process was successful or unsuccessful. The precise way to do that will depend on what programming language you use.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .