Mvn exec: exec with '<' on the Args command line

I need to run a command containing '<' in it.

I can run it from the command line, but it throws an error when I put it in mvn exec.

Team:

c:\apps\putty\plink.exe [email protected] -T -ssh -2 $SHELL /dev/stdin 'a b c d' < test.sh

test.sh:

#!/bin/bash
echo "execution parameters: [email protected]"

Command line output:

runtime options: abcd

pom.xml:

<plugin> 
                <groupId>org.codehaus.mojo</groupId> 
                <artifactId>exec-maven-plugin</artifactId> 
                <version>1.4.0</version> 
                <executions> 
                    <execution>
                        <id>test</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration><executable>c:\apps\putty\plink.exe</executable>
                            <commandlineArgs>"[email protected] -T -ssh -2 $SHELL /dev/stdin 'a b c d' < test.sh"</commandlineArgs>
                        </configuration>
                    </execution>
            </executions> 
        </plugin> 

I tried changing '<' to '& lt;' by putting commandlineArgs in CDATA, putting doubleqoutes (") everywhere, but couldn't make it work.

[DEBUG] Executing command line: [c:\apps\putty\plink.exe, > [email protected] -T -ssh -2 -pw tomcat  $SHELL /dev/stdin 'a b c d' &lt; test.sh] 
Unable to open connection: Host does not exist[INFO]
------------------------------------------------------------------------ 
[INFO] BUILD FAILURE

or

[DEBUG] Executing command line: [c:\apps\putty\plink.exe, [email protected], -T, -ssh, -2, -pw, tomcat, $SHELL /dev /stdin 'a b c d' &lt; test.sh] 
bash: test.sh: No such file or directory [INFO]
------------------------------------------------------------------------ 
[INFO] BUILD FAILURE

I suspect the '<' parameter, but I'm not sure what the problem is.

Any tips?

UPDATE: ", '<' to '& lt;', commandlineArgs CDATA, doubleqoutes (" ) , ." - !

+4
3

, .bat :

@echo off
set plinkExec=%1
set env=%2
set user=%3
set pass=%4
set shellPath=%5
...

%plinkExec% %user%@%env% -T -ssh -2 -pw %pass% $SHELL /dev/stdin '...' < %shellPath%

, : -)

+1

. - .

,

  • notepad.exe myfile.txt
  • java -jar my-program.jar

exec API (Java java.lang.Runtime.getRuntime().exec(), PHP ..).

, , Maven , .

, . , , , . :

            <configuration>
                <executable>bash</executable>
                <arguments>
                    <argument>-c</argument>
                    <argument>java -jar myprogram.jar < input.txt > output.txt</argument>
                </arguments>
            </configuration>

Windows,

            <configuration>
                <executable>path/to/cmd.exe</executable>
                <arguments>
                    <argument>/C</argument>
                    <argument>java -jar myprogram.jar < input.txt > output.txt</argument>
                </arguments>
            </configuration>

- , . Groovy.

, .

0

You specifically asked mvn exec:exec. But assuming you rather need to execute a redirect command, another way is to use a plugin that can handle the threads yourself, for example. Maven Ant Plugin. Pay attention to input="...":

        <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.8</version>
            <executions>
                <execution>
                    <phase>verify</phase>
                    <goals> <goal>run</goal> </goals>
                    <configuration>
                        <target name="run">
                            <exec dir="${work.dir}" executable="java" input="input.txt">
                                <arg value="-jar"/>
                                <arg file="${project.build.directory}/${project.build.finalName}.jar"/>
                            </exec>
                        </target>
                    </configuration>
                </execution>
            </executions>
        </plugin>            
0
source

Source: https://habr.com/ru/post/1628956/


All Articles