1

Firstly, the bash script works fine when I call it outside of ant. Here is the relevant part of the build.xml

<exec executable="/bin/bash" failonerror="true">
<arg value="-c" />
<arg value="script.sh" />
</exec>

Here is the relevant line in the bash script (script.sh):

nc -l 8044 | tee ./nc-out.txt &

When I call script.sh from bash, the contents of nc-out.txt get populated with the data sent to port 8044.

I require the ampersand there.

When the shell script is called from ant, it seems as if nc-out.txt is created, but stays empty.

A normal redirect such as:

nc -l 8044 > nc-out.txt & 

Also does not work..

Any insight would be useful!

Thanks!

3
  • Is this the same issue as your previous question? Commented Jun 20, 2012 at 12:53
  • Clearly different, started a new post because it seems to be related to ant. Commented Jun 20, 2012 at 13:08
  • Ah ok. If it's not the stdin issue, my guess would be buffering, but if ant is somehow to blame I probably can't help. Commented Jun 20, 2012 at 13:12

2 Answers 2

1

When ant exec your command its standard input is by default not tied to anything, so netcat will exits right away when you connect to the listening process since there is nothing more to read from stdin.

Since you want to run it in the background I assume that you only want to achieve a one-way logging : you can add the -d parameter to netcat to tell him not to read from standard input:

script.sh

#/bin/bash
netcat -d -l 8044 > nc-out.txt &

Fully working with the following ant build file example :

build.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="script" name="bleh">
    <target name="script">
        <exec executable="/bin/bash" failonerror="true">
            <arg value="-c" />
            <arg value="./script.sh" />
        </exec>
    </target>
</project>
Sign up to request clarification or add additional context in comments.

2 Comments

@GregorioDiStefano I added my full code example, and it works like a charm for me. Running ant in the build directory leaves the nc process in the background and I can successfully connect to it and see the output in the nc-out.txt file, even when no TTY is attached to the background nc anymore.
@GregorioDiStefano - you already tried the -d option? You didn't state that in your question. Please update your question with all relevant tests you have done.
0

I suggest adding spawn="true" to your exec to give the background process you are creating its own life.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.