Run a external command in a custom console

已回答

I want to build a custom run configuration which involves executing an external bat file. The challenge here is that this particular bat file can run reliably only when another bat file is executed before it, because it sets many environment variables which are required.

The straightforward option here was to use a command line string like "C:\Users\user\common.bat && C:\Users\user\dependent.bat". But I haven't been able to get this work. When I build the corresponding CommandLine object it treats the second script as an argument and not as a command. Something like this - C:\Users\user\common.bat "C:\Users\user\dependent.bat".

I looked into CommandLine class implementation and it clearly treats the first command as the exe path and other as arguments. I tried the OSProcessHandler(Process) constructor to achieve my target but that also doesn't work properly. Moreover, that is deprecated as well so I dont want to put a lot of effort on that strategy.

So to summarize, my plugin requires that common environment be setup before any external script can be run reliably. What is the proper way to achieve this?

0

Probably, you can do it by passing smth like ["cmd.exe", "/C", "call", "file1.bat", "&&", "call", "file2.bat"].

`.bat` is not an executable file, so it can't be executed by OSProcessHandler.
It might work for a single file, because `com.intellij.plugins.watcher.TaskRunnerImpl` has a shortcut for executing a single bat script (but it doesn't work in your case).

0

请先登录再写评论。