Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filename too long #8

Closed
neil-benn opened this issue Oct 22, 2020 · 9 comments
Closed

Filename too long #8

neil-benn opened this issue Oct 22, 2020 · 9 comments

Comments

@neil-benn
Copy link

When running this as a simpe test; the code is:
// Specify JVM options (optional)
RootExecutor rootExecutor = new RootExecutor("-Xmx64m");

	// Execute privileged action without return
	rootExecutor.run(() -> System.out.println("rmdir \"c:\\Program Files\\test-remove"));

I get an error:

java.io.IOException: Cannot run program ""C:\Users\neilb\AppData\Local\Temp\run-as-root18038586148998856981-elevate"": CreateProcess error=206, The filename or extension is too long

The OS in Win10 64 bit; is there a way to get the filename length down?

@dyorgio
Copy link
Owner

dyorgio commented Oct 22, 2020

Hi @neil-benn, tks to open this issue ;).
This link: StackOverflow Post suggests that filename is not the problem, but the classpath.

Take a look in OutProcessUtils.getCurrentClasspath() output (call it in your current project main) and verify if is possible to reduce... you can construct your classpath manually too... Copy source of RootExecutor in a new file and replace OneRunOutProcess constructor call with one that accepts custom classpath.

You maybe will like to use OutProcessUtils.generateClassPath(Class...).

Let me know if you could solve this, I will update library with a new RootExecutor constructor.

@neil-benn
Copy link
Author

neil-benn commented Oct 22, 2020

You are correct; this is a spring boot app so there are a lot of jars in the classpath. It's not so easy to reduce the classpath so something that says 'do not inherit the current classpath would solve the issue. I was just trawling through your source code for outprocess when I came to the same conclusion :).

@neil-benn
Copy link
Author

Yep that worked - the actual test doesn't work but the process runs with elevated permissions. Teh new constructor is:

/**
 * Creates an instance with specific java options, the classpath can be specified
 * this is useful if you have a lng classpath that breaks commadn line restrictions on Windows
 *
 * @param classPath a custom classpath
 * @param javaOptions JVM options (ex:"-xmx32m")
 */
public RootExecutor(String classPath, String[] javaOptions) throws IOException {
    this.outProcess = new OneRunOutProcess(MANAGER, classPath, javaOptions);
}

@neil-benn
Copy link
Author

However; the fundamental underlying call isn't working too well; I am executing:

	RootExecutor rootExecutor = new RootExecutor(".", new String[] {"-Xmx64m"});
	String command =  "mkdir \"C:\\Program Files\\test-elevate\"";
	System.out.println("executing " + command);
	rootExecutor.run(() -> System.out.println(command));

However; no directory is created. I've obviously checked this in command prompt and it works (as admin) but not in rootexecutor. Am I doing something wrong in the command format?

@neil-benn
Copy link
Author

Nope; no matter what I try the command always returns '1' and fails. The elevation works perfectly but the command doesn't.

@dyorgio
Copy link
Owner

dyorgio commented Oct 22, 2020

I see two problems:

  1. System.out.println will only print argument on process output, not exec command... It is just an example on README :D. Replace with Runtime.exec.
  2. "." as classpath is not sufficient, because at least RootExecutor, OutProcess and deps needs to be on classpath.

Use OutProcessUtils.generateClassPath(RootExecutor.class, OneRunOutProcess.class, YOURCLASSTHATISCREATINGLAMBDAORINNERCLASS.class)

@neil-benn
Copy link
Author

Thanks; the sysout did seem really weird to me! I see what you mean about the classpath; in fact because of FST it is massive. I note that in the source you have got rid of FST. I think I'll need that version as this makes the dependent libraries much lighter.

@dyorgio
Copy link
Owner

dyorgio commented Oct 23, 2020

Done! Version 1.2.3 was released.
Please, note that maybe it take some time to you find it on maven respository.

@dyorgio
Copy link
Owner

dyorgio commented Nov 26, 2020

Closed by timeout.

@dyorgio dyorgio closed this as completed Nov 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants