Hello,
I have a bit of code that needs to execute a shell script... I have a working (I think) runtime function to execute the code... but I always get an exit code of 1 when I run it... what does that mean? I cant seem to find documentation of it.
Here is the code:
//start a parallel campaign
Datasource db = new Datasource();
if (campaign.get("listname").
toString()
.length() <= 0)
{
String listname = "/tmp/list" + generateUniqueFilename();
String query = "select id,email from " + campaign.get("tablename").
toString()
+ " where email NOT IN (select email from unsubscribes where client_id = " + campaign.get("client_id").
toString()
+ ") and email not in (select email from " + campaign.get("suppressiont
able").toS
tring() + ");";
//now execute the cli command to generate the list required for the campaign
String command = "sh /home/rick/controlcenter/c
reateListD
ata.sh '" + query + "' " + listname;
System.out.println("SH Execution: " + execCLI(command));
//now open the datasource
//db.openDatasource(listna
me,0);
//campaign.put("listname",
listname);
}
else
db.openDatasource(campaign
.get("list
name").toS
tring(),ne
w Long(campaign.get("lastrow
").toStrin
g()).longV
alue());
//servers.parallelCampaign
(db,campai
gn);
String generateUniqueFilename()
{
Date d = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("MMddyyyy
hhmmssSSS"
);
return sdf.format(d);
}
int execCLI(String command)
{
int retval = -1;
try
{
System.out.println(command
);
Runtime rt = Runtime.getRuntime();
Process p = rt.exec(command);
p.waitFor();
retval = p.exitValue();
}
catch(IOException ie)
{
System.out.println(ie.getM
essage());
}
catch(InterruptedException
i)
{
System.out.println(i.getMe
ssage());
}
return retval;
}
Here's the Output:
sh /home/rick/mailpro3control
center/cre
ateListDat
a.sh 'select id,email from testlist where email NOT IN (select email from unsubscribes where client_id = 1) and email not in (select email from suppression091920070115308
89);' /tmp/list09302007011205564
SH Execution: 1
A correct fix is worth 500 points.
Thanks,
Rick