Launch Script From Java always return Exit code = 1

231 views
Skip to first unread message

Davide Vichi

unread,
Apr 24, 2021, 11:21:28 AM4/24/21
to ack users
Hello Guys,
I need to run the "ack" command directly from a Java program on Eclipse, it just doesn't work and returns exit code = 1.
If I run the same shell command, it works perfectly.

The command is very simple and is as follows:

ack 11290013 UIM.csv
i want to look for the id number inside the csv. However, the csv is very large (2.5GB).


- I tried to run eclipse as super user, the "ack" command is recognized but something goes wrong.
- I'm using apache.common.exec
- I have Mac 10.15.7 Catalina
- I installed ack via home brew
- I also tried including the command in an external bash script and running that script from Java.

Thanks for any form of help
Regards

Andy Lester

unread,
Apr 24, 2021, 11:24:56 AM4/24/21
to ack-...@googlegroups.com
>
> I need to run the "ack" command directly from a Java program on Eclipse, it just doesn't work and returns exit code = 1.
> If I run the same shell command, it works perfectly.


Can you see any of the output from ack when you run it in Eclipse? Do you get an error message? Can you run other things than ack from inside Eclipse?

My first thought, without knowing anything else, is that somehow you have your PATH different between Eclipse and your shell. Or, it could be PERL5LIB, and ack can’t find the standard libraries.


>
> - I tried to run eclipse as super user, the "ack" command is recognized but something goes wrong.

We need more details about the “something goes wrong”. It doesn’t sound like you’re doing anything weird.

What if you just run “ack -h”, where it doesn’t do anything but show a help screen?

I think if we can get some more details, we’ll get this figured out.



Davide Vichi

unread,
Apr 24, 2021, 12:07:02 PM4/24/21
to ack-...@googlegroups.com
Hi Andy,
Thanks for your quick reply

 Can you see any of the output from ack when you run it in Eclipse?  Do you get an error message?
 
When I run the command from Eclipse

"ack 11290013 UIM.csv"

 I get only the following error

org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)

and no more... this is the section code:

String line = "ack 11290013 UIM.csv";
CommandLine cmdLine = CommandLine.parse(line);
DefaultExecutor executor = new DefaultExecutor();
executor.setWorkingDirectory(new File("/Users/davidevichi/csvkit_tutorial/"));
int exitValue = executor.execute(cmdLine, procEnv);
System.out.println("Process exit code: " + exitValue);


My first thought, without knowing anything else, is that somehow you have your PATH different between Eclipse and your shell.  Or, it could be PERL5LIB, and ack can’t find the standard libraries.

I can confirm that the PATH variable is the same between Eclipse and shell. Initially it wasn't, then I found a way to set it up..

Map<String, String> procEnv = EnvironmentUtils.getProcEnvironment();
procEnv.put("PATH", "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin");

maybe it is PERL that needs to be configured properly but i don't know how to do it.

What if you just run “ack -h”, where it doesn’t do anything but show a help screen?
 
I had not tried this test in fact. I confirm that "ack --help" WORKS perfectly in Eclipse! (invoked in the same way as above).

Some detail about the first ack command:
- UIM.csv it's a very huge file 2,5GB
-  "11290013" it's a product id and I want to read the line containing the product details.

Thanks in advance
Best Regards 


Davide



--
You received this message because you are subscribed to the Google Groups "ack users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ack-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ack-users/93AC687F-E2F6-4529-BC43-B8114AE89EC9%40petdance.com.


--

Mike Kelly

unread,
Apr 25, 2021, 10:45:08 AM4/25/21
to ack users
Not a solution per se but I’d suggest ack is overkill for what you’re trying to do here.  Ack is optimized for  searching code — you’re searching a simple CSV data file.  Have you tried using grep?  I bet you could build a grep pipeline into sed or cut that would give you in Java just what you want from that CSV line.

Mike Kelly
Tech DNA

Andy Lester

unread,
Apr 25, 2021, 5:28:37 PM4/25/21
to ack-...@googlegroups.com


On Apr 25, 2021, at 9:45 AM, Mike Kelly <mrmicha...@gmail.com> wrote:

Have you tried using grep?  I bet you could build a grep pipeline into sed or cut that would give you in Java just what you want from that CSV line.

Indeed, what happens when you try ack instead of grep?

Davide Vichi

unread,
Apr 26, 2021, 2:27:26 AM4/26/21
to ack-...@googlegroups.com
Hi Guys,
grep and also csvgrep (from csvkit) for this huge file in the worst case (the pattern is present in the last line) spents 35 secs. 
ack spents only 2,5 seconds!


Anyway, since the "ack --help" command works, why the "ack 123 UIM.csv" command doesn't?
maybe a particular perl environment variable needs to be included?

Thanks in advance

Regards











--
You received this message because you are subscribed to the Google Groups "ack users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ack-users+...@googlegroups.com.


--

Andy Lester

unread,
Apr 27, 2021, 9:47:21 AM4/27/21
to ack-...@googlegroups.com


On Apr 26, 2021, at 1:27 AM, Davide Vichi <davide...@engynya.com> wrote:

grep and also csvgrep (from csvkit) for this huge file in the worst case (the pattern is present in the last line) spents 35 secs. 
ack spents only 2,5 seconds!

If ack is 14x faster than grep in searching through a single text file, then there’s something strange going on.  There is no case where ack should be faster, much less 14x faster, reading through a single file.

I’m wondering what else might be going on here.
Reply all
Reply to author
Forward
0 new messages