0

I've a fairly rudimentary knowledge of batch files and usually manage to get by but have hit a problem which I can't solve.

The batch files are run on Windows 7 Ultimate and Windows 10 Professional systems and are usually invoked by a Scheduler program, although sometimes I just click the relevant desktop icon. Essentially, the role of the batch files is to download specific files (TV programmes) which are listed in an external text file, in my case, located in my Dropbox account. For each item in the text file (TV.txt) there are two lines, one naming the file, the other listing its ID:

name1
ID1
name2
ID2
name3
ID3

The batch files successively work through the items listed in the text file, one file works on the "IDs", the second on the "names".

The "IDs" file (tv-pid.cmd) consists of the following:

set $textFile="D:\Dropbox\Get_iPlayer\0-TVdl\tv.txt"
for /f "delims=" %%a in ('type %$textFile%') do get_iplayer --pid %%a

The "names" file (tv-nopid.cmd) consists of the following:

set $textFile="D:\Dropbox\Get_iPlayer\0-TVdl\tv.txt"
for /f "delims=" %%a in ('type %$textFile%') do get_iplayer --get %%a

Each batch file works well on its own, the problem is when I try to combine the two into a single batch file.

If I create a "combined" batch file (tv.cmd):

call tv-pid.cmd
call tv-nopid.cmd

the first "call" is executed but the batch operation terminates before calling the second file.

Equally if I create a "combined" batch file (not using "call" commands)

set $textFile="D:\Dropbox\Get_iPlayer\0-TVdl\tv.txt"
for /f "delims=" %%a in ('type %$textFile%') do get_iplayer --pid %%a
set $textFile="D:\Dropbox\Get_iPlayer\0-TVdl\tv.txt"
for /f "delims=" %%a in ('type %$textFile%') do get_iplayer --get %%a

the same happens, the download activity on line 2 is executed after which the batch operation terminates.

Personally I would prefer a solution based on the "call" commands, but I don't mind.

user338034
  • 433
  • 1
  • 4
  • 8
  • 4
    This: http://stackoverflow.com/questions/14731877/a-bat-file-call-or-not-to-call-that-is-the says _all batch file processing will cease (control will not return to the caller) if the CALLed batch file has a fatal syntax error._ So it seems there are reasons it may exit completely. What if you use `cmd /c` instead as suggested by that post? – Nick.Mc Apr 02 '17 at 06:36
  • 1
    Since I'm not familiar with `get_iplayer`, I'd suggest `call get_iplayer` may solve the problem, but I'll post a longer response which may be easier still. – Magoo Apr 02 '17 at 06:45
  • Thank you, Nick.McDermaid, problem sorted! It works a treat now! – user338034 Apr 02 '17 at 06:54
  • Your suggestion is my accepted answer, Nick.McDermain. How do indicate this? Thanks. – user338034 Apr 02 '17 at 07:05
  • I recommend you wait another day or two to see if @Nick wants to post his own answer. If he doesn't, post an answer yourself (and accept it) making sure of course that you give credit to Nick. – Harry Johnston Apr 03 '17 at 02:34
  • @Mofi, I don't mind you amending the title for it to be more meaningful, but I take great exception to "TV Programmes" being amended to "TV Programs". I am based in the UK from where the English language originates. Thankfully we're not yet totally in an Americanised world! Please change it back. – user338034 Apr 03 '17 at 08:02

1 Answers1

3
set $textFile="D:\Dropbox\Get_iPlayer\0-TVdl\tv.txt"
set "idnames="
for /f "delims=" %%a in ('type %$textFile%') do (
 if defined id_names (
  set "id_names="
  call get_iplayer --pid %%a
 ) else (
  set "id_names=Y"
  call get_iplayer --get %%a
 )

This may work. I've no idea what get_iplayer is or does.

The idea here is that the line-content alternates, so toggling the variable id_names between set-to-a-value and set-to-no-value (=cleared) allows us to execute get_iplayer with the correct options.

Note that your code would execute get_iplayer with the option pid or get for each line of the input file - which may be causing the problem.

Magoo
  • 77,302
  • 8
  • 62
  • 84
  • Magoo, I have specific reasons for executing on both name and PID, which I won't go into here. In any case, after the first "call" the batch operation terminates and it never gets as far as the second "call". But I thank you for your swift response. Thanks. – user338034 Apr 02 '17 at 07:09
  • Perhaps you could use `start "" get_iplayer...` - that would set each `get_iplayer` instance established as its own independent job. Here's http://stackoverflow.com/questions/43060025/is-there-a-more-efficient-way-to-watermark-and-join-videos-in-bulk-through-ffmpe/43064770#43064770 a reference on how to limit the number of parallel operations. – Magoo Apr 02 '17 at 07:35