batch script returns unexpectedly after first asciidoctor command completion

51 views Asked by At

I just created a batch file to build documentation in asciidoctor and installer in inno setup.
I noticed that calls to asciidoctor commands cause immediate return from the script. Call to iscc allows calls to subsequent commands (I was shuffling the order to find the reason). Should asciidoctor call obtain some additional argument?

@echo off
setlocal
set "SolutionDir=%1"
echo POST-BUILD
set "filePath=%SolutionDir%SlitapScheduler\bin\Release\SlitapScheduler.exe"
echo %filePath%
set "filePath=%filePath:\=\\%"

for /f "usebackq delims=" %%a in (`wmic DATAFILE WHERE "name='%filePath%'" get Version /format:Textvaluelist`) do (
    for /f "delims=" %%# in ("%%a") do set "%%#"
)

echo %Version%

asciidoctor -V 
REM below this line commands are not executed

echo :::HTML generation:::
asciidoctor -v -t -a release-version=%Version% "%SolutionDir%Docs\SlitapScheduler.adoc"

echo :::PDF generation:::
asciidoctor-pdf -v -t -a release-version=%Version% "%SolutionDir%Docs\SlitapScheduler.adoc"

echo :::SETUP generation:::
iscc /O+ "%SolutionDir%Setup\neu_inno_script.iss"


endlocal
C:\project\SlitapScheduler\Setup>a C:\project\SlitapScheduler\
POST-BUILD
C:\project\SlitapScheduler\SlitapScheduler\bin\Release\SlitapScheduler.exe
1.0.0.16
Asciidoctor 2.0.20 [https://asciidoctor.org]
Runtime Environment (ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x64-mingw-ucrt]) (lc:IBM437 fs:UTF-8 in:UTF-8 ex:UTF-8)
1

There are 1 answers

1
PiotrBzdrega On

It turned out that asciidoctor commands preceded by a call expression allowed to run successfully subsequent calls.

Edit: As guys mentioned in the comments, asciidoctor is .rb ruby script (control will not return to the caller in this case).

############################## asciidoctor.rb ####################################
#!/usr/bin/env ruby
# frozen_string_literal: true

asciidoctor = File.absolute_path '../lib/asciidoctor.rb', __dir__
if File.exist? asciidoctor
  require asciidoctor
  require File.join Asciidoctor::LIB_DIR, 'asciidoctor/cli'
else
  require 'asciidoctor'
  require 'asciidoctor/cli'
end

invoker = Asciidoctor::Cli::Invoker.new ARGV
GC.start
invoker.invoke!
exit invoker.code