how to debug shell execution processes?

W

Wilfried

Hello all,
I contribute to the latex2rtf converter project by compiling the DOS /
Windows port.

I'd like to get a hint how to debug the following problem (or, even
better, to solve it).

The program is written in C with command line interface and works as
intended under Mac OSX, Linux, cygwin and Windows (MinGW compiler).

I only have problems when a lot of equations are to be converted to
bitmaps.
The process is as follows:
- latex2rt.exe writes a LaTeX snippet to a disk file
- latex2rt.exe issues a SYSTEM call which starts bash
(from http://sourceforge.net/projects/win-bash/ )
- - which runs the shell script latex2png
- - which
- - - runs some shell utilities from
http://sourceforge.net/projects/gnuwin32/
- - - calls LaTeX (MikTeX) to convert .tex to .dvi
- - - calls dvips (MikTeX) to convert .dvi to .eps
- - - calls ImageMagick (Windows version) to convert .eps to .png
- - - calls ImageMagick to crop the .png
- latex2rt.exe reads the .png file and includes it in the rtf output.

The processing stops under XP
- when invoked from a freshly opened command prompt, after converting at
most about 600 equations (sufficient for most documents),
- but when some other commands were run in the command prompt before
invoking latex2rtf, it stops after about 100 equations.
- If the command prompt is opened from the windows GUI (l2rshell.exe),
it also stops after fewer equations.
- If additional debug output is written to stderr (i.e. the command
prompt), it stops after about 8 equations.

Under Vista, the number of successfully converted equations is generally
lower than under XP.
Interestingly, when running in cygwin under Vista, an error message is
issued: "... bash.exe: *** fatal error - couldn't allocate heap ..."

I read
http://wikis.sun.com/display/OpenJdkBuilds/Known+OpenJDK+Build+Problems
(scroll down to "Windows CYGWIN Problems")
and also looked at
http://cygwin.com/faq/faq.using.html#faq.using.bloda
so I tried with (temporarily) uninstalling the virus scanner, but this
didn't help.

The Windows port (including installer) and the source (platform
independent) are on
http://sourceforge.net/projects/latex2rtf/
latex2rtf-win package, version 1.9.20, pre-release

Many thanks for any hint how to debug this.
 
F

foxidrive

The processing stops under XP
- when invoked from a freshly opened command prompt, after converting at
most about 600 equations (sufficient for most documents),
- but when some other commands were run in the command prompt before
invoking latex2rtf, it stops after about 100 equations.

What is an example of the other commands?
- If the command prompt is opened from the windows GUI (l2rshell.exe),
it also stops after fewer equations.
- If additional debug output is written to stderr (i.e. the command
prompt), it stops after about 8 equations.

How does the process stop? With an error message? Lockup?
Exit normally?

Re the process: is a single equation a single pass through the script?
 
W

Wilfried

foxidrive said:
What is an example of the other commands?

E.g. calling "l2r.bat" which in turn
sets some environment variables
calls latex2rt.exe
and ends.
The batch file completes normally and returns to the original command
prompt, but some resources seem to be irreversibly consumed.

Calling latex2rt.exe from a freshly opened command prompt under XP, it
stopped after about 310 equations.
I then started latex2rt.exe again from the same command prompt, and it
stopped after 167 equations.
I again started latex2rt.exe from the same command prompt, and it
stopped after 119 equations.

-> I'll have to investigate whether all opened files are correctly
closed.
How does the process stop? With an error message? Lockup?
Exit normally?

Depends.

Under XP, just stops after processing an equation and returns to the
command prompt without error message, but the generated rtf file is
incomplete. The shellscript was successfully executed on the (n)th tex
file (temporary files were deleted) but the (n+1)th tex file isn't
written to disk.
That reminds me of a thing. The program tests whether the tex file can
be opened for writing. It seems that after successfully writing n tex
files to disk, the "open for writing" of the n+1 file fails and
therefore the program exits.

Under Vista, mostly crash: "latex2rt has stopped working ... looking for
solution". It seems that the "open for writing" does not return the
correct state under Vista.
Re the process: is a single equation a single pass through the script?

Yes.

Thanks for your reply.
Wilfried
 
F

foxidrive

E.g. calling "l2r.bat" which in turn
sets some environment variables
calls latex2rt.exe
and ends.
The batch file completes normally and returns to the original command
prompt, but some resources seem to be irreversibly consumed.


Depends.

Under XP, just stops after processing an equation and returns to the
command prompt without error message, but the generated rtf file is
incomplete. The shellscript was successfully executed on the (n)th tex
file (temporary files were deleted) but the (n+1)th tex file isn't
written to disk.
That reminds me of a thing. The program tests whether the tex file can
be opened for writing. It seems that after successfully writing n tex
files to disk, the "open for writing" of the n+1 file fails and
therefore the program exits.

This could be central to the issue - maybe something to do with shared temp
files, or too many temp files open.

Have you considered rewriting the script using windows commands to see if
that changes the behaviour?
 
W

Wilfried

This could be central to the issue - maybe something to do with shared temp
files, or too many temp files open.

Have you considered rewriting the script using windows commands to see if
that changes the behaviour?

I rewrote the script but this didn't change anything.

I then stripped down the calling program so that only a (constant)
input file for the script is written and the script is called. This
runs successfully for at least 500 equations. So it is neither the
script nor the programs called by the script.

Finally I modified the calling program so that no system call is
issued and therefore the script is not run. The error still occurs. So
it must be a bug in the calling program (e.g. failing to close a
file).

Thank you for pointing me to the right questions. I think the rest of
the debugging does not belong into this group.

Wilfried
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top