user1578872
user1578872

Reputation: 9048

Bytebuddy - Arguments for agent premain

I have a premain as below for attaching an agent to a remote process.

public static void premain(String args, Instrumentation instrumentation) {

    System.out.println("Premain");
    File file ;
    try {

            file = (new File("Agent.jar"));
            ByteBuddyAgent.attach(file,"18467");
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }

}

Here, I want to pass the process id and couple of other arguments. Is there anyway to do this. Looks like it takes one single argument.

java -javaagent:/path/to/agent.jar -cp jar-under-test.jar Foo.Main

How can i pass the argument here?

Upvotes: 0

Views: 215

Answers (1)

Rafael Winterhalter
Rafael Winterhalter

Reputation: 44032

You would need to encode the argument in any manner you find appropriate. Instead of spaces as used for the arguments to main, use commas for example but escape all existing commas, for example by doubling them. In the agent, split by single commas and reverse the escaping for the resulting segments.

Upvotes: 1

Related Questions