V
V
Valery Chupurnov2019-04-15 12:13:11
IntelliJ IDEA
Valery Chupurnov, 2019-04-15 12:13:11

How in JetBrains idea plugin to execute on the command line with an argument consisting of several lines?

Good time. I am writing my own linter for a custom language. Linter is written in JS, and the IDE plugin communicates with it via the command line.
At first, I sent only the path of the file to the linter, but then it turned out that the IDE does not save the file right away, and what was in the editor did not always correspond to what was in the file.
I decided to send the contents of the file to the linter at the time of editing from the editor.
More or less like this

import com.intellij.execution.configurations.GeneralCommandLine;
...
GeneralCommandLine commandLine = new GeneralCommandLine();
commandLine.withCharset(StandardCharsets.UTF_8)
                .setWorkDirectory(cwd);

commandLine.setExePath(StylusLinterExe);
commandLine.addParameter(file);

if (StringUtils.isNotEmpty(content)) {
    commandLine.addParameter("--content");
    commandLine.addParameter(content);
}

This works fine on mac, but in widows only one line gets into the content parameter - the very first one.
You need to somehow escape the line breaks.
The matter is that Java I am not strong. Tell me please. It only came to mind to replace all the hyphens with some sequence of characters and replace them back with js, but this is such a solution.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question