Jump to content

Start bot in java application


Recommended Posts

Posted (edited)
11 minutes ago, The Undefeated said:

I use this code to start the bot in a java application:


        String completeCLI = "java -jar \"root/Desktop/osbot.jar\"";
        System.out.println(completeCLI);
        Process proc = Runtime.getRuntime().exec(completeCLI);
        proc.waitFor();

This works in Windows, but not in Ubuntu. Anyone knows how I can start my client in Ubuntu?

 

 

Tested and seems to work:

ProcessBuilder processBuilder = new ProcessBuilder("java", "-jar", "/home/user/explv/Downloads/OSBot 2.4.121.jar");
processBuilder.start();

 

Edited by Explv
Posted (edited)
14 minutes ago, Explv said:

 

Tested and seems to work:


ProcessBuilder processBuilder = new ProcessBuilder("java", "-jar", "/home/user/explv/Downloads/OSBot 2.4.121.jar");
processBuilder.start();

 

But how can I add CLI parameters to it now? Can't figure that out.

ProcessBuilder doesn't allow a 3rd argument.

Edited by The Undefeated
Posted (edited)
16 minutes ago, The Undefeated said:

But how can I add CLI parameters to it now? Can't figure that out.

ProcessBuilder doesn't allow a 3rd argument.

The ProcessBuilder constructor accepts either a List<String> or String...

Each item in the List or String[] is one parameter of the command.

So, for example:

List<String> command = new ArrayList<>();
Collections.addAll(command, "java", "-jar", "/path/to/osbot.jar", "-script", "890:none");
ProcessBuilder pBuilder = new ProcessBuilder(command);

or

String[] command = {"java", "-jar", "/path/to/osbot.jar", "-script", "890:none"};
ProcessBuilder pBuilder = new ProcessBuilder(command);

or

ProcessBuilder pBuilder = new ProcessBuilder("java", "-jar", "/path/to/osbot.jar", "-script", "890:none");

 

Edited by Explv
Posted (edited)
33 minutes ago, Explv said:

The ProcessBuilder constructor accepts either a List<String> or String...

Each item in the List or String[] is one parameter of the command.

So, for example:


List<String> command = new ArrayList<>();
Collections.addAll(command, "java", "-jar", "/path/to/osbot.jar", "-script", "890:none");
ProcessBuilder pBuilder = new ProcessBuilder(command);

or


String[] command = {"java", "-jar", "/path/to/osbot.jar", "-script", "890:none"};
ProcessBuilder pBuilder = new ProcessBuilder(command);

or


ProcessBuilder pBuilder = new ProcessBuilder("java", "-jar", "/path/to/osbot.jar", "-script", "890:none");

 

This only starts the bot and doesn't log it in.

String[] command = {"java","-jar","osbot.jar","-login \"The Undefeated\":password"};
        ProcessBuilder pBuilder = new ProcessBuilder(command);
        pBuilder.start();
Edited by The Undefeated
Posted
20 minutes ago, The Undefeated said:

This only starts the bot and doesn't log it in.


String[] command = {"java","-jar","osbot.jar","-login \"The Undefeated\":password"};
        ProcessBuilder pBuilder = new ProcessBuilder(command);
        pBuilder.start();

"-login" and "username:password" should be two separate items in the array:

String[] command = {"java","-jar","osbot.jar","-login", "\"The Undefeated\":password"};

 

Posted (edited)
8 minutes ago, Explv said:

"-login" and "username:password" should be two separate items in the array:


String[] command = {"java","-jar","osbot.jar","-login", "\"The Undefeated\":password"};

 

Forgot to mention I already tested that and didn't even start, might be caused by the space in my name. Even tried it like this but won't start either.

String[] command = {"java","-jar","osbot.jar","-login", "\"The", "Undefeated\":password"};

 

Edited by The Undefeated
Posted (edited)
33 minutes ago, The Undefeated said:

Shows the exact same behavior as I stated in my comment above.

 

Oh sorry I thought you knew. You need your own login handler since all randoms are disabled, or if your using non-cli paramters and just using this to start simple scripts then you can remove the -norandoms flag in my code.

If you end up using the custom login handler, you will need to pass the bot login info as parameters since you cant access those hidden fields normally. You can make your own or I think Explv may have a snippet of some somewhere on here.

Edited by LoudPacks
Posted (edited)
10 hours ago, LoudPacks said:

Oh sorry I thought you knew. You need your own login handler since all randoms are disabled, or if your using non-cli paramters and just using this to start simple scripts then you can remove the -norandoms flag in my code.

If you end up using the custom login handler, you will need to pass the bot login info as parameters since you cant access those hidden fields normally. You can make your own or I think Explv may have a snippet of some somewhere on here.

If you read my post above I said the whole client doesn't even start. I know what norandoms does and I have my own login handler but those make no sense if I can't even open the client.

EDIT: Got it working by putting my username in quotation marks.

 

Edited by The Undefeated
Posted
13 hours ago, The Undefeated said:

Forgot to mention I already tested that and didn't even start, might be caused by the space in my name. Even tried it like this but won't start either.


String[] command = {"java","-jar","osbot.jar","-login", "\"The", "Undefeated\":password"};

 

 

Try:

String[] command = {"java", "-jar", "osbot.jar", "-login", "\"\\\"The Undefeated\\\":password\""};

 

 

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...