I run a bash script from my Java program which takes a chunk of data, manipulates it, and splits it up.
It's not a question of whether the bash script works -- I can see the split files in the directory.
Say the original file was "bigFile" in data/
Then
try
{
Process proc = Runtime.getRuntime().exec("bash " + SCRIPT_DIR + "/" + SPLIT_SCRIPT_NAME + " " + args[_MESSAGES_PER_UPLOAD_] + " " + args[_MAXIMUM_MESSAGES_PER_FEED_] + " " + (60000*Integer.parseInt(args[_DURATION_BEFORE_EACH_UPLOAD_IN_MINUTES_])/Integer.parseInt(args[_DURATION_OF_EACH_FEED_IN_MILLISECONDS_])));
proc.waitFor();
}
catch(IOException e) { error(e); }
String fileNames;
File folder = new File(DATA_DIR);
File[] filesToUpload = folder.listFiles();
for (int i = 0; i < filesToUpload.length; ++i)
if (filesToUpload[i].isFile())
{
fileNames = filesToUpload[i].getName();
System.out.println(fileNames);
}
Will print bigFile, not...
$ ls data/
dataChunk_00000 dataChunk_00001 dataChunk_00002 dataChunk_00003 dataChunk_00004 dataChunk_00005 dataChunk_00006 dataChunk_00007 dataChunk_00008 dataChunk_00009 dataChunk_00010 dataChunk_00011 dataChunk_00012 dataChunk_00013 dataChunk_00014 dataChunk_00015 dataChunk_00016 dataChunk_00017 dataChunk_00018 dataChunk_00019 dataChunk_00020 dataChunk_00021 dataChunk_00022 dataChunk_00023 dataChunk_00024 dataChunk_00025 dataChunk_00026 dataChunk_00027
as it should. I'm guessing this is a compiler optimization or something.
Edit: If somebody could explain to me why proc.waitFor() isn't working and/or a better way to solve this, I'd much appreciate it.
Runtime.exec(String[])instead of.exec(String)like you're doing here, for all but the absolute simplest things.Runtime.exec()is not a shell or parser and doesn't honor quoting or escaping. Providing all your arguments in a single string can often lead to unexpected treatment of arguments becauseexec(String)blindly splits on spaces.