Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#240 closed defect (fixed)

Starting java.exe from ash/dash breaks command line arguments with spaces

Reported by: dmik Owned by:
Priority: major Milestone: GA6
Component: general Version: 1.6.0 Build 27 GA5
Severity: medium Keywords:


Given this

public class hello
  public static void main(String args[])
    System.out.println("hello world!");
    for (int i = 0; i < args.length; ++i)

and this SH script:

D:/Tools/openjdk6_b27_sdk_os2_ga5-20130217/bin/java.exe -cp . hello "1 2" 3

you get this output if the script is run by bash:

hello world!
arg[0]=[1 2]

and this output if it's run by ash/dash:

hello world!

Apparently, in the second case spaces are handled incorrectly.

Change History (4)

comment:1 Changed 4 years ago by dmik

Note that if you take a normal C test like this:

#define INCL_BASE
#include <os2.h>

#include <alloca.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

int main(int argc, const char **argv)
  printf ("Hello, world!\nHello, Universe!\n");

  PPIB ppib;
  DosGetInfoBlocks(NULL, &ppib);
  char *s = ppib->pib_pchcmd;
  while (*s)
    printf ("pchcmd [%s]\n", s);
    s += strlen(s) + 1;

  int i;
  for (i = 0; i < argc; ++i)
    printf ("arg[%d]=[%s]\n", i, argv[i]);
  return 0;

and run this script:

hello.exe "1 2" 3

the result are as follows for bash:

Hello, world!
Hello, Universe!
pchcmd [hello.exe]
pchcmd ["1 2" 3]
arg[1]=[1 2]

and for ash/dash:

Hello, world!
Hello, Universe!
pchcmd [../hello.exe]
pchcmd [kLIBC]
pchcmd [ 1 2]
pchcmd [ 3]
arg[1]=[1 2]

You may see that the raw command line (pib_pchcmd) differs because kLIBC applies special processing to it to improve performance when handling arguments in exec/spawn and fork for kLIBC-based executables, but the result you see through the standard argv vector are identical (as they should be).

So my bet is that our Java launchers try to play with the raw command line and don't take all the details into account (I recall that I did something in that area now I need to find the place).

comment:2 Changed 4 years ago by dmik

Okay, I got why it breaks. We actually go Windows way a lot there due to heavy use of Odin and we in particular use Odin's RegisterLxExe() and __argcA/__argvA which are of course set directly right from the raw command line. There are hacks that work around KLIBC specifics but they are not perfect and don't properly process everything. We should fix it in Odin I guess. Sigh.

comment:3 Changed 4 years ago by dmik

Resolution: fixed
Status: newclosed

I fixed this in Odin, see Now Java processes arguments with spaces and with quotes in them correctly. In other words, running the above snippet from dash/ash produces exactly the same results as from the old, EMX-based bash.

comment:4 Changed 4 years ago by dmik

The DLLs from the test Odin build are here (just in case if you want to test w/o rebuilding Odin):

Note: See TracTickets for help on using tickets.