Strange ls & fork

This weekend, I rewrote internal parts of some (darkbat, flatbat, autoflat, meandark, kombine) utilities. The utilities are internally divided into two parts. A wrapper part made interaction of a second part (core of execution) with its environment and user. The core itself provides a required functionality. The wrapper runs the core as a sub-process and both parts communicates via a pipes (output of wrapper is connected to input of core) I did it by a module coded myself (primary for Nightview). The code uses system call fork (along with related ones). Now, It has been replaced by popen system call to simplify and standardize of wrapper's code. The change include some lost of efficiency of code (a shell is invoked) but additional occupied resources are insignificant.

My code to run sub-process work correctly but it has some in-advantages:
  • the code is non-standard (developers usually abuse on ones)
  • it's complicated to use (requires to use of more complex code)
The most important reported error appears for environments with system PATH variable set-up without current directory (without dot). The system reports (Thx to Kočka, M.Zaťko) following strange error:

$ ls * | mdark @
MEANDARK Version 0.1, Copyright (C) 1997-06 F.Hroch, Masaryk

Subprocess execution failed: No such file or directory: mdark.bin

Nevertheless, both mdark and mdark.bin has correct permissions and the same parent directory. To solve the problem, simply add dot to your system path (for bash: export PATH=$PATH:.) or install any newer version of Munipack.

The separation of code to the wrapper and the core has mostly historical reason. Fortran didn't supported UNIX environment up to version Fortran 2003. All implementations contains some unofficial extensions but it may be syntactically different (for example ifc, g95, gfortran,g77 vs. SUN's Fortran). The separation also provide another additional advantages. The core can be used separately as a part of another great code without any connection to a command line fronted (represented by the wrapper). For example, the core can be easily used in some graphical or web environment.

Also, I found some confusing behaviour of system command ls (list of files in directory). When ls is aliased in zsh (bash?, tcsh?) by the way

ls='ls -F --color'

(color is crucial) we get this really strangle error reporting

$ ls -F --color image.fits | mdark @
MEANDARK Version 0.2, Copyright (C) 1997-08 F.Hroch, Masaryk University,Brno,CZ

The following error(s) has been occured:
input file URL is missing closing bracket ']'
could not parse the input filename: (ffopen)

Of course, it is due to hidden escape sequences which doing output list coloured. I have no idea how to suppress it or how recognize these color marks on input. You has been warned.
Post a Comment