Search code examples
javajarzxing

Runing .jar with argument that contains char ">" and some strange things happen


I have a .jar file, calling it like this:

java -jar qr-0.1.jar message=])rsfkoekfoe023k20f9k0fk3oi43jf

The code generates an pdf417 qr image, and drops it at c:/tmp, all outputs are displayed in the console.

The problem is when I put the character > in the message, like so:

java -jar qr-0.1.jar message=])>rsfkoekfoe023k20f9k0fk3oi43jf

This creates an random file next to the jar with the console output inside, and the pdf417 qr image encodes only the first two characters :/

The thing is, when I debug, the message with the char > works fine, it breaks only when i create the jar file.

This is how i set arguments in code:

for(String arg : args){
        String[] argument = arg.split("=");
        keyword = argument[0];
        if(argument.length>1){
            value = argument[1];
        }

        if(keyword.equals(KEY_MESSAGE)){
            message = value;
        }
        else if(keyword.equals(KEY_WIDTH)){
            w = Integer.parseInt(value);
        }
        else if(keyword.equals(KEY_HEIGHT)){
            h = Integer.parseInt(value);
        }
        else if(keyword.equals(KEY_FILENAME)){
            fileName = value;
        }
        else if(keyword.equals(KEY_FILEPATH)){
            filePath = value;
        }
    }

Solution

  • Put it like this:

    java -jar qr-0.1.jar message="])>rsfkoekfoe023k20f9k0fk3oi43jf"
    

    Or by escaping special characters using backslash