Post Reply 
 
Thread Rating:
  • 1 Votes - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
K shell child processes
2012-07-11, 02:41 PM
Post: #1
K shell child processes
I have a UNIX script that I run in a K shell. It spawns a FORTRAN program which then executes a second K shell script (via SYSTEM) running a second FORTRAN program. This sort of thing works just fine under "real" UNIX, AIX and HP-UX. Not so well under SUA and Windows 7.

On Windows 7 starting from a K shell window I can execute the script which starts my FORTRAN program just fine. But SYSTEM cannot execute my second K shell script. How can I make SYSTEM execute my second K shell script as a K shell script where it will work just as it should? Thanks for any suggestions.
Find all posts by this user
Quote this message in a reply
2012-07-11, 04:37 PM
Post: #2
RE: K shell child processes
What errors do you get? I've used system() from C programs just fine. It invokes /bin/sh, which is not guaranteed to be the Korn shell. If your script starts with #!/bin/ksh I would expect it to work, though. Have you tried running the second script directly from the terminal, preferably with something like "/bin/sh secondscript.sh", just to test it?
Find all posts by this user
Quote this message in a reply
2012-07-12, 03:24 AM (This post was last modified: 2012-07-12 03:25 AM by rodney.)
Post: #3
RE: K shell child processes
I'm guessing the FORTRAN program is a Win32 binary.
Because of this the idea of what the system() API should do is different from the Unix sense.
Since the shell script is "text" and doesn't have in it's binary executable header the marker that it's Interix/SUA,
the Win32 system() API doesn't know what to do.

From your FORTRAN program (and this will be true for any Win32 program) you will need to have a command
that looks like the shortcut on the desktop or in the menu for starting an Interix/SUA shell.
To run a specific shell script there will be just a minor addition of the path to the script (the Unix path).
For example:
posix.exe /u /c /bin/ksh -lc /tmp/my_second_script
This will start a terminal window , run ksh with the login option (likely needed because the Win32 program
may have tossed Unix expected environment data) and then the script will run.
If you don't want to have a terminal window appear then your can use PSXRUN.EXE instead of POSIX.EXE.
There are manual pages for both ("man psxrun" & "man posix").
The example with PSXRUN is very similar; minor difference because it has slightly different options:
psxrun.exe -u -p /bin/ksh -- ksh -lc /tmp/my_second_script

N.B. When I state "Win32" I include "Win64" as well.
Find all posts by this user
Quote this message in a reply
2012-07-12, 12:32 PM
Post: #4
RE: K shell child processes
Rodney, will definitely give this a try. Thank you very much.

On Windows XP my scripts with a ".ksh" extension were "KorhShellScript" and opened with "Interix Utility" and they had the little pyramid icon. Double clicking them executed them as Korn Shell scripts. On Windows 7 they have no association and double clicking them just makes Windows 7 unhappy. Do you know of a way to get that double click association with Interix back?
Find all posts by this user
Quote this message in a reply
2012-07-12, 03:24 PM
Post: #5
RE: K shell child processes
Interix has a working FORTRAN compiler, right? If your program expects to be used on UNIX-like systems, might it be better to recompile under Interix rather than using Win32 at all?

iowa_don, it's a hack, but creating a .CMD file with the following text
Code:
posix /u /c /bin/sh -l -c "`winpath2unix '%~f1'` '%2' '%3' '%4' '%5' '%6' '%7' '%8' '%9'"
and then setting it as the "open with" target for .sh/.ksh/whatever appears to work. It's probably possible to use the registry association directly, rather than going through a CMD script, but it does (sort of) work. A more graceful version would also do things like preseve the working directory and such; Rodney probably knows a better way.
Find all posts by this user
Quote this message in a reply
2012-07-12, 05:47 PM
Post: #6
RE: K shell child processes
The FORTRAN compiler is from a 3rd party (not from Microsoft or from here).
There are two actually: one from PGI and the other from Intel.
Find all posts by this user
Quote this message in a reply
2012-07-12, 05:50 PM
Post: #7
RE: K shell child processes
Rodney, any way to get the ".ksh" windows XP file association I had using Windows 7 as I mentioned above earlier today?
Find all posts by this user
Quote this message in a reply
2012-07-12, 06:43 PM
Post: #8
RE: K shell child processes
For file extension associations I can't remember what MS did back with Interix/SFU 3.5.
What you can do (besides what cbhacking has suggested) is doing it with some obscure DOS commands.
Yup, no GUI AFAIK to do this (I just tried to find some way by GUI -- waste of time).
There are two commands you'll have to use: assoc and ftype.
Open a CMD.EXE window as the Administrator (that's important so you have enough permission to do this).
Then enter:

assoc .sh=InterixScript
ftype InterixScript="%WINDIR%\posix.exe /u /c /bin/ksh -lc" "%*"


Change the ".sh" to ".ksh" if you want -- or add both.
The "%*" gets all of the args to the command.
You may need to reboot for the cache to get refreshed.

This won't get you the Interix pyramid because Microsoft stopped including the pyramid as the exe ICON during the build. *blah*
If you really, really, really need the pyramid to appear it can be done but it's convoluted.
Find all posts by this user
Quote this message in a reply
2012-07-12, 07:55 PM
Post: #9
RE: K shell child processes
Wouldn't passing the parameter list directly cause the Korn shell to recieve the script file in Win32 path form? That's why I did the song-and-dance with backticks and winpath2unix.

Also, both assoc and ftype are actually available from within Interix; they're in the /usr/contrib/win32/bin/ folder that is automatically added to path, and are implemented as shell scripts that convert parameters as needed and then call the Win32 binaries (not DOS at all, although they are command-line apps). Of course, then you have to deal with the Interix shell's command line processing on your ftype parameter. The following works for me:
Code:
sudo assoc .sh=InterixScript
sudo assoc .ksh=InterixScript
sudo ftype InterixScript=C:\\Windows\\posix.exe /u /c /bin/sh -l -c "\`winpath2unix '%1'\` '%*'"

For the icon (and a description), you'll probably need to edit the registry more directly (although that's all that the assoc.exe and ftype.exe utilities are; simple ways to tweak the HKEY_CLASSES_ROOT registry hive). If you want to be able to open shell scripts straight from web pages, you'll also need to add an EditFlags registry value of 0x00010000 (at least) tot he HKCR\InterixScript key.
Put this is a .reg file and merge it (I'm assuming a fairly standard Interix install path of C:\Windows\SUA here).
Code:
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\InterixScript]
@="Interix shell script"

[HKEY_CLASSES_ROOT\InterixScript\DefaultIcon]
@="C:\\Windows\\SUA\\etc\\interix.ico"
Find all posts by this user
Quote this message in a reply
2012-07-13, 01:19 AM
Post: #10
RE: K shell child processes
> Wouldn't passing the parameter list directly cause the Korn shell to recieve the script file in Win32 path form?

Yes, for the path to the script it'll have to be converted from win-speak to unix-speak.

That ".reg" thing is good.
For folks that don't yet know, the most current updates to the shells include the package "logoico" which
has a better looking pyramid logo (32 bit instead of 16 bit). You can install this by itself if you don't want to
install the shell packages (pkg_update -L logico). It puts it in /etc/interix.ico.
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)