Java -jar “/users/admin/Sample code/sample.jar” -

2019-09-01 04:55发布

I'm trying to trigger a payload installation using java with the help of this code from the command window:

" java -jar "/users/admin/Sample code/sample.jar" -payloads "/users/admin/Sample code/payloads" -logfile testing.log -loglevel FINE "

But because of the space present in the directory '/users/admin/Sample code/sample.jar', exception is being thrown.

How can i rectify this ?

1条回答
不美不萌又怎样
2楼-- · 2019-09-01 05:52

(If my understanding is correct, this is more of a shell interpolation problem than a Java problem, so you might want to modify the tags to reflect this.)

This is going to be tricky because you need to know how many levels of parsing this command line is going to go through until some command processor shell does it's own parsing. At the end of this whole thing we are hoping to have all the tokens presented to the java process in the manner we expect.

That's the general problem.

Assuming you are running this directly from a shell (I think that's what "command window" means -- I'm trying to be careful here) then it depends on how that shell parses the command into tokens, and passes control to the Java process. For example, on Windows the sort of necessary and available quoting is different, and behaves differently, than POSIX shells.

The specific problem, then, is protecting this space as significant for the shell you are running the command in, such that the java process sees its arguments, and then the Java program that launches as a result sees /its/ arguments in the right manner.

You don't mention which shell you are running, or which of the arguments is failing (the argument to java, or the argument to the java program that is invoked. So it is hard to hand you specific help.

But, if you are using a POSIX shell of some sort, you could use one (or more) backslash escapes on the offending spaces in either part until you get the results you want. Or use nested strong quotes to suppress interpolation by the shell or java main().

You might want to say what sort of program this is, and how you are running it, and on what platform, and what results you are getting, exactly. It is important to know where in this startup process the error is being thrown.

[EDIT]

I see you are probably on a POSIX shell of some sort, in which case, you should be able to use single-quotes or backslash escaping to protect the spaces in these arguments [either to the Java process or the main()].

[EDIT]

Given that this is a POSIX shell, and it appears to be failing to find a startup file, either the jarfile is missing this class or the jar manifest file is malformed. Does this class exist, exactly as spelled (case is significant!) in the jarfile? Remember that a class name must match exactly across the class definition in the code, in the filename/jarfile entry and in the manifest file.

That is, it appears that the JVM is finding the jarfile without a problem, but when it loads the jarfile to get the manifest info and the startup class, it fails to find that. So, this seems to be a problem with the jarfile itself, not that fact that your -jar optargs has a space in it.

查看更多
登录 后发表回答