Skip to content

Setting output file #8

Description

@dariober

Hello- I've started using jawk as a library within a Java program. Thanks for making it available.

What I'm trying to do should be pretty standard: Read a file as InputStream, parse it through jawk, collect the output from jawk. The problem is that the output of jawk seems to go to stdout instead of to the file I set.

This is what I'm doing:

@Test
public void testAwk() throws Exception{

    InputStream is= new FileInputStream("test_data/hg19_genes_head.gtf"); // File to parse

    String[] args= {"-F", "\t", "NR < 10"}; // Trivial awk script

    AwkParameters parameters = new AwkParameters(Main.class, null);
    AwkSettings settings = parameters.parseCommandLineArguments(args);

    settings.setInput(is); 
    settings.setOutputFilename("/tmp/foo.txt"); // Here is where I expect the output to go.

    Awk awk= new Awk();
    awk.invoke(settings);
}

When I execute testAwk() I see the first ten lines of the input file printed to stdout and the supposed output file "/tmp/foo.txt" is not even created.

I also tried setting the output file in the awk script: String[] args= {"-o", "/tmp/foo.txt", "-F", "\t", "NR < 10"} and I got the same result.

In either case the output of settings.getOutputFilename(null) is "/tmp/foo.txt".

What am I doing wrong? And more in general, is the above the recommended strategy to use jawk as a library in a Java program?

Many thanks!

Dario

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions