Shell command not executing in Java [duplicate] - java

This question already has an answer here:
shell Command execution Failing when executed from Java
(1 answer)
Closed 9 years ago.
Normally when i do this:
printf 'select x from Y \ngo\n' | isql -Uxx -Pxxxxxx -Dxxxxx -w 65535 -s ','
on the command line it executes fine.
even with the below java code. it works fine
public class test
{
public static void main(String[] args)
{
String DB="|isql -Uxx -Pxxxxxx -Dxxxxx -w 65535 -s ','";
String qpfx="printf \'";
String qsfx=" \ngo\n\'";
if(args[0]!=null)
try {
String cmd=qpfx+args[0]+qsfx+DB;
System.out.println("argument query is:"+args[0]);
System.out.println("Command is:"+cmd);
Process p = Runtime.getRuntime().exec(new String[]{"sh","-c",cmd});
p.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line=reader.readLine();
while (line != null) {
System.out.println(line);
line = reader.readLine();
}
}
catch(IOException e1) {}
catch(InterruptedException e2) {}
}
}
I will run this above java code like below:
java test "select x from Y"
Probelm comes when i give the select query as "select * from Y" instead of column names.
That is when i wanted to execute like below:
java test "select * from Y"
The above jav code hangs.Can any body tell me the reason why?
below is the output where its hanging:
> java test "select * from Y"
argument query is:select * from Y
Command is:printf 'select * from Y
go
'|isql -Uxx -Pxxxxx -Dxxxxxx -w 65535 -s ','
I also tried:
java test "select \* from Y"
But it does not execute.

After severe debugging i found that the line that is hanging is p.waitFor();.
I had to read this complete article and then i finally found a solution.
I have shifted the p.waitFor(); after the while loop in the code and it worked.

Related

RServe: control pipe to master process is closed/broken

I have this R script:
palindrome <- function(p) {
for(i in 1:floor(nchar(p)/2) ) {
r <- nchar(p) - i + 1
if ( substr(p, i, i) != substr(p, r, r) ) return(FALSE)
}
return(TRUE)
}
that I am calling from Java using the following code:
connection.serverSource("C:\\Users\\x\\Desktop\\R Script\\Palindrome.R");
the connection is of type RConnection is created as follows:
public void startConnection() {
PATH_TO_R = SystemUtils.IS_OS_UNIX ? "R" : "C:\\Program Files\\R\\R-3.6.1\\bin\\x64\\R.exe";
try {
String cmd = PATH_TO_R + " -e " + "\"library(Rserve);Rserve(port=" + 6311+ ")\"";
Runtime.getRuntime().exec(cmd);
RConnection connection = new RConnection("localhost", 6311);
} catch (IOException | RserveException e) {
e.printStackTrace();
}
}
The problem is I am having this error thrown and have no idea how to fix it:
org.rosuda.REngine.Rserve.RserveException: serverSource failed, request status: control pipe to master process is closed/broken
any help will be much appreciated!
The function serverSource (just like serverEval and serverShutdown) directly works on the main R+Rserve process, this feature is off by default. You can enable it in /etc/Rserv.conf adding the line control enabled (config reference).
If you don't already use an Rserve config file, you can simply create it in the default location /etc/Rserv.conf (linux/macOS) or create it anywhere (also windows) and pass the location as parameter when starting Rserve: R CMD Rserve --RS-conf <your path here> (command line arguments at the bottom of the page).

Issue executing a piped ps unix command through Runtime.exec()

Issue:
When executing the following command through Runtime.exec(...), it fails with an unexpected EOF while looking for a matching quote character.
One oddity is that the error message has a grave character followed by two single quotes.
However, when I execute the command that prints out in the logs through putty, it works fine.
Command:
bin/sh -c 'ps -eo uname,pid,ppid,nlwp,pcpu,pmem,psr,start_time,tty,time,args | fgrep IAAPC | fgrep /f1/f2/a00-a/f3/server/server_1/env_1/javadriver | fgrep -v fgrep'
Resulting error:
-eo: -c: line 0: unexpected EOF while looking for matching `''
-eo: -c: line 1: syntax error: unexpected end of file
Java Code (Java 1.6 ... Don't Judge):
String driverHome = trimToEmpty(System.getProperty("batchdriver.home"));
String cmd = "/bin/sh -c 'ps -eo uname,pid,ppid,nlwp,pcpu,pmem,psr,start_time,tty,time,args | fgrep "+jobName+" | fgrep "+driverHome+" | fgrep -v fgrep'";
String out = null, err = null;
Process proc = null;
try {
proc = Runtime.getRuntime().exec(cmd);
out = fullyRead(proc.getInputStream());
err = fullyRead(proc.getErrorStream());
int exitVal = proc.waitFor();
if(logger.isDebugEnabled()) {
logger.debug("Process Information: "+out);
}
if (isNotEmpty(err)) {
logger.error(failedCommandMessage(cmd, out, err));
this.processId = null;
this.processDesc = PROCESS_NOT_FOUND;
return;
}
String[] processes = StringUtils.split(out, "\r?\n");
if (processes == null || processes.length == 0) {
this.processDesc = PROCESS_NOT_FOUND;
}
else if (processes.length == 1) {
String[] processInfo = processes[0].split("\\s+");
this.processId = processInfo[1];
if (!isNumeric(this.processId)) {
this.processId = null;
}
this.processDesc = out;
}
else {
this.processDesc = out;
}
if (logger.isDebugEnabled()) {
logger.debug("Call to the OS completed with exit value: " + exitVal);
}
} catch (Exception e) {
try {out = fullyRead(proc.getInputStream());} catch (Exception e1) {}
try {err = fullyRead(proc.getErrorStream());} catch (Exception e1) {}
this.processId = null;
this.processDesc = PROCESS_NOT_FOUND;
logger.error(failedCommandMessage(cmd, out, err), e);
}
Related but not quite dupe: Pass a string with multiple contiguous spaces as a parameter to a jar file using Windows command prompt called from a java program
The Runtime.exec methods that take a String break it into tokens at whitespace only so this actually runs the program /bin/sh (a shell) with the following arguments:
-c
'ps
-eo
uname,pid,ppid,nlwp,pcpu,pmem,psr,start_time,tty,time,args
|
fgrep
...
The shell interprets these arguments like this:
-c 'ps -- the script to run consists of the apostrophe character, p, s (and nothing more)
-eo -- the name of the command being run is -eo
uname,pid,.... -- the first argument to the script is this
| -- the second argument to the script is this
fgrep -- the third argument to the script is this
...
-- but the script ignores the arguments and doesn't use them
Thus you get
-eo: -c: unexpected EOF while looking for matching `''
# the script named -eo, with the option -c having value 'ps,
# tried to find a closing ' to match the opening ' and it's not there
This shell is apparently (GNU) bash; many GNU programs that put a data string in an error message surround it by backquote and apostrophe because these were sort of matching quotes in one interpretation of ASCII popular decades ago.
Instead use the String[] overload of exec to give the shell the two arguments that it gets when your above command line is parsed by a shell instead of StringTokenizer:
String[] cmdary = {"/bin/sh", "-c", "ps -eo stuff | fgrep this | fgrep that | fgrep -v fgrep"};
... Runtime.getRuntime().exec(cmdary);
But instead of running three fgrep's, you could just run the ps and read the inputstream as lines and test them in Java using String.contains or similar. Also most of the columns you ask ps for will never be used for either your matching nor result, so that's just a waste of effort and clutter.

How to pass a string value of length greater than 255 to a processbuilder in java

I am having a command having a length greater than 255. The command is a Sqoop (Hadoop) import which loads data into the hive from a RDBMS. I am using the ProcessBuilder API which provide two constructors
ProcessBuilder(String[] command)
ProcessBuilder(List<String> command)
I tried passing the command in both the ways as mentioned above
ssh hddev-chost-01-01 "sqoop import -D oraoop.disabled=true -D mapred.child.java.opts='\-Djava.security.egd=file:/dev/../dev/urandom' --connect 'jdbc:oracle:thin:#(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=maildude.com)(PORT=1533))(CONNECT_DATA=(SERVICE_NAME=SDA.COM)(Server=Dedicated)))' --username user --password pass --query \"select INVENTORY_ITEM_ID,ORGANIZATION_ID,LAST_UPDATE_DATE,LAST_UPDATED_BY,CREATION_DATE,CREATED_BY,LAST_UPDATE_LOGIN,SUMMARY_FLAG,ENABLED_FLAG,START_DATE_ACTIVE,END_DATE_ACTIVE,DESCRIPTION,BUYER_ID,ACCOUNTING_RULE_ID,INVOICING_RULE_ID,SEGMENT1,SEGMENT2,SEGMENT3,SEGMENT4,SEGMENT5,SEGMENT6,SEGMENT7,SEGMENT8,SEGMENT9,SEGMENT10,SEGMENT11,SEGMENT12,SEGMENT13,SEGMENT14,SEGMENT15,SEGMENT16,SEGMENT17,SEGMENT18,SEGMENT19,SEGMENT20,ATTRIBUTE_CATEGORY,ATTRIBUTE1,ATTRIBUTE2,ATTRIBUTE3,ATTRIBUTE4,ATTRIBUTE5,ATTRIBUTE6,ATTRIBUTE7,ATTRIBUTE8,ATTRIBUTE9,ATTRIBUTE10,ATTRIBUTE11,ATTRIBUTE12,ATTRIBUTE13,ATTRIBUTE14,ATTRIBUTE15,PURCHASING_ITEM_FLAG,SHIPPABLE_ITEM_FLAG,CUSTOMER_ORDER_FLAG,INTERNAL_ORDER_FLAG,SERVICE_ITEM_FLAG,INVENTORY_ITEM_FLAG,ENG_ITEM_FLAG,INVENTORY_ASSET_FLAG,PURCHASING_ENABLED_FLAG,CUSTOMER_ORDER_ENABLED_FLAG,INTERNAL_ORDER_ENABLED_FLAG,SO_TRANSACTIONS_FLAG,MTL_TRANSACTIONS_ENABLED_FLAG,STOCK_ENABLED_FLAG,BOM_ENABLED_FLAG,BUILD_IN_WIP_FLAG,REVISION_QTY_CONTROL_CODE,ITEM_CATALOG_GROUP_ID,CATALOG_STATUS_FLAG,RETURNABLE_FLAG,DEFAULT_SHIPPING_ORG,COLLATERAL_FLAG,TAXABLE_FLAG,QTY_RCV_EXCEPTION_CODE,ALLOW_ITEM_DESC_UPDATE_FLAG,INSPECTION_REQUIRED_FLAG,RECEIPT_REQUIRED_FLAG,MARKET_PRICE,HAZARD_CLASS_ID,RFQ_REQUIRED_FLAG,QTY_RCV_TOLERANCE,LIST_PRICE_PER_UNIT,UN_NUMBER_ID,PRICE_TOLERANCE_PERCENT,ASSET_CATEGORY_ID,ROUNDING_FACTOR,UNIT_OF_ISSUE,ENFORCE_SHIP_TO_LOCATION_CODE,ALLOW_SUBSTITUTE_RECEIPTS_FLAG,ALLOW_UNORDERED_RECEIPTS_FLAG,ALLOW_EXPRESS_DELIVERY_FLAG,DAYS_EARLY_RECEIPT_ALLOWED,DAYS_LATE_RECEIPT_ALLOWED,RECEIPT_DAYS_EXCEPTION_CODE,RECEIVING_ROUTING_ID,INVOICE_CLOSE_TOLERANCE,RECEIVE_CLOSE_TOLERANCE,AUTO_LOT_ALPHA_PREFIX,START_AUTO_LOT_NUMBER,LOT_CONTROL_CODE,SHELF_LIFE_CODE,SHELF_LIFE_DAYS,SERIAL_NUMBER_CONTROL_CODE,START_AUTO_SERIAL_NUMBER,AUTO_SERIAL_ALPHA_PREFIX,SOURCE_TYPE,SOURCE_ORGANIZATION_ID,SOURCE_SUBINVENTORY,EXPENSE_ACCOUNT,ENCUMBRANCE_ACCOUNT,RESTRICT_SUBINVENTORIES_CODE,UNIT_WEIGHT,WEIGHT_UOM_CODE,VOLUME_UOM_CODE,UNIT_VOLUME,RESTRICT_LOCATORS_CODE,LOCATION_CONTROL_CODE,SHRINKAGE_RATE,ACCEPTABLE_EARLY_DAYS,PLANNING_TIME_FENCE_CODE,DEMAND_TIME_FENCE_CODE,LEAD_TIME_LOT_SIZE,STD_LOT_SIZE,CUM_MANUFACTURING_LEAD_TIME,OVERRUN_PERCENTAGE,MRP_CALCULATE_ATP_FLAG,ACCEPTABLE_RATE_INCREASE,ACCEPTABLE_RATE_DECREASE,CUMULATIVE_TOTAL_LEAD_TIME,PLANNING_TIME_FENCE_DAYS,DEMAND_TIME_FENCE_DAYS,END_ASSEMBLY_PEGGING_FLAG,REPETITIVE_PLANNING_FLAG,PLANNING_EXCEPTION_SET,BOM_ITEM_TYPE,PICK_COMPONENTS_FLAG,REPLENISH_TO_ORDER_FLAG,BASE_ITEM_ID,ATP_COMPONENTS_FLAG,ATP_FLAG,FIXED_LEAD_TIME,VARIABLE_LEAD_TIME,WIP_SUPPLY_LOCATOR_ID,WIP_SUPPLY_TYPE,WIP_SUPPLY_SUBINVENTORY,PRIMARY_UOM_CODE,PRIMARY_UNIT_OF_MEASURE,ALLOWED_UNITS_LOOKUP_CODE,COST_OF_SALES_ACCOUNT,SALES_ACCOUNT,DEFAULT_INCLUDE_IN_ROLLUP_FLAG,INVENTORY_ITEM_STATUS_CODE,INVENTORY_PLANNING_CODE,PLANNER_CODE,PLANNING_MAKE_BUY_CODE,FIXED_LOT_MULTIPLIER,ROUNDING_CONTROL_TYPE,CARRYING_COST,POSTPROCESSING_LEAD_TIME,PREPROCESSING_LEAD_TIME,FULL_LEAD_TIME,ORDER_COST,MRP_SAFETY_STOCK_PERCENT,MRP_SAFETY_STOCK_CODE,MIN_MINMAX_QUANTITY,MAX_MINMAX_QUANTITY,MINIMUM_ORDER_QUANTITY,FIXED_ORDER_QUANTITY,FIXED_DAYS_SUPPLY,MAXIMUM_ORDER_QUANTITY,ATP_RULE_ID,PICKING_RULE_ID,RESERVABLE_TYPE,POSITIVE_MEASUREMENT_ERROR,NEGATIVE_MEASUREMENT_ERROR,ENGINEERING_ECN_CODE,ENGINEERING_ITEM_ID,ENGINEERING_DATE,SERVICE_STARTING_DELAY,VENDOR_WARRANTY_FLAG,SERVICEABLE_COMPONENT_FLAG,SERVICEABLE_PRODUCT_FLAG,BASE_WARRANTY_SERVICE_ID,PAYMENT_TERMS_ID,PREVENTIVE_MAINTENANCE_FLAG,PRIMARY_SPECIALIST_ID,SECONDARY_SPECIALIST_ID,SERVICEABLE_ITEM_CLASS_ID,TIME_BILLABLE_FLAG,MATERIAL_BILLABLE_FLAG,EXPENSE_BILLABLE_FLAG,PRORATE_SERVICE_FLAG,COVERAGE_SCHEDULE_ID,SERVICE_DURATION_PERIOD_CODE,SERVICE_DURATION,WARRANTY_VENDOR_ID,MAX_WARRANTY_AMOUNT,RESPONSE_TIME_PERIOD_CODE,RESPONSE_TIME_VALUE,NEW_REVISION_CODE,INVOICEABLE_ITEM_FLAG,TAX_CODE,INVOICE_ENABLED_FLAG,MUST_USE_APPROVED_VENDOR_FLAG,REQUEST_ID,PROGRAM_APPLICATION_ID,PROGRAM_ID,PROGRAM_UPDATE_DATE,OUTSIDE_OPERATION_FLAG,OUTSIDE_OPERATION_UOM_TYPE,SAFETY_STOCK_BUCKET_DAYS,AUTO_REDUCE_MPS,COSTING_ENABLED_FLAG,AUTO_CREATED_CONFIG_FLAG,CYCLE_COUNT_ENABLED_FLAG,ITEM_TYPE,MODEL_CONFIG_CLAUSE_NAME,SHIP_MODEL_COMPLETE_FLAG,MRP_PLANNING_CODE,RETURN_INSPECTION_REQUIREMENT,ATO_FORECAST_CONTROL,RELEASE_TIME_FENCE_CODE,RELEASE_TIME_FENCE_DAYS,CONTAINER_ITEM_FLAG,VEHICLE_ITEM_FLAG,MAXIMUM_LOAD_WEIGHT,MINIMUM_FILL_PERCENT,CONTAINER_TYPE_CODE,INTERNAL_VOLUME,WH_UPDATE_DATE,PRODUCT_FAMILY_ITEM_ID,GLOBAL_ATTRIBUTE_CATEGORY,GLOBAL_ATTRIBUTE1,GLOBAL_ATTRIBUTE2,GLOBAL_ATTRIBUTE3,GLOBAL_ATTRIBUTE4,GLOBAL_ATTRIBUTE5,GLOBAL_ATTRIBUTE6,GLOBAL_ATTRIBUTE7,GLOBAL_ATTRIBUTE8,GLOBAL_ATTRIBUTE9,GLOBAL_ATTRIBUTE10,PURCHASING_TAX_CODE,OVERCOMPLETION_TOLERANCE_TYPE,OVERCOMPLETION_TOLERANCE_VALUE,EFFECTIVITY_CONTROL,CHECK_SHORTAGES_FLAG,OVER_SHIPMENT_TOLERANCE,UNDER_SHIPMENT_TOLERANCE,OVER_RETURN_TOLERANCE,UNDER_RETURN_TOLERANCE,EQUIPMENT_TYPE,RECOVERED_PART_DISP_CODE,DEFECT_TRACKING_ON_FLAG,USAGE_ITEM_FLAG,EVENT_FLAG,ELECTRONIC_FLAG,DOWNLOADABLE_FLAG,VOL_DISCOUNT_EXEMPT_FLAG,COUPON_EXEMPT_FLAG,COMMS_NL_TRACKABLE_FLAG,ASSET_CREATION_CODE,COMMS_ACTIVATION_REQD_FLAG,ORDERABLE_ON_WEB_FLAG,BACK_ORDERABLE_FLAG,WEB_STATUS,INDIVISIBLE_FLAG,DIMENSION_UOM_CODE,UNIT_LENGTH,UNIT_WIDTH,UNIT_HEIGHT,BULK_PICKED_FLAG,LOT_STATUS_ENABLED,DEFAULT_LOT_STATUS_ID,SERIAL_STATUS_ENABLED,DEFAULT_SERIAL_STATUS_ID,LOT_SPLIT_ENABLED,LOT_MERGE_ENABLED,INVENTORY_CARRY_PENALTY,OPERATION_SLACK_PENALTY,FINANCING_ALLOWED_FLAG,EAM_ITEM_TYPE,EAM_ACTIVITY_TYPE_CODE,EAM_ACTIVITY_CAUSE_CODE,EAM_ACT_NOTIFICATION_FLAG,EAM_ACT_SHUTDOWN_STATUS,DUAL_UOM_CONTROL,SECONDARY_UOM_CODE,DUAL_UOM_DEVIATION_HIGH,DUAL_UOM_DEVIATION_LOW,CONTRACT_ITEM_TYPE_CODE,SUBSCRIPTION_DEPEND_FLAG,SERV_REQ_ENABLED_CODE,SERV_BILLING_ENABLED_FLAG,SERV_IMPORTANCE_LEVEL,PLANNED_INV_POINT_FLAG,LOT_TRANSLATE_ENABLED,DEFAULT_SO_SOURCE_TYPE,CREATE_SUPPLY_FLAG,SUBSTITUTION_WINDOW_CODE,SUBSTITUTION_WINDOW_DAYS,IB_ITEM_INSTANCE_CLASS,CONFIG_MODEL_TYPE,LOT_SUBSTITUTION_ENABLED,MINIMUM_LICENSE_QUANTITY,EAM_ACTIVITY_SOURCE_CODE,LIFECYCLE_ID,CURRENT_PHASE_ID,OBJECT_VERSION_NUMBER,CDB_DATA_SOURCE,CDB_ENQUEUE_TIME,CDB_DEQUEUE_TIME,CDB_ENQUEUE_SEQ from MTL_SYSTEM_ITEMS_B where \\\$CONDITIONS \" --target-dir /app/dev/SmartAnalytics/sqoop_temp//MTL_SYSTEM_ITEMS_B -m 4 --split-by INVENTORY_ITEM_ID --hive-import --hive-overwrite --hive-table installbase.MTL_SYSTEM_ITEMS_B --null-string '\\\\N' --null-non-string '\\\\N' --hive-delims-replacement '<EOL>' --map-column-hive INVENTORY_ITEM_ID=BIGINT,ORGANIZATION_ID=BIGINT,LAST_UPDATE_DATE=TIMESTAMP,LAST_UPDATED_BY=BIGINT,CREATION_DATE=TIMESTAMP,CREATED_BY=BIGINT,LAST_UPDATE_LOGIN=BIGINT,SUMMARY_FLAG=STRING,ENABLED_FLAG=STRING,START_DATE_ACTIVE=TIMESTAMP,END_DATE_ACTIVE=TIMESTAMP,DESCRIPTION=STRING,BUYER_ID=BIGINT,ACCOUNTING_RULE_ID=BIGINT,INVOICING_RULE_ID=BIGINT,SEGMENT1=STRING,SEGMENT2=STRING,SEGMENT3=STRING,SEGMENT4=STRING,SEGMENT5=STRING,SEGMENT6=STRING,SEGMENT7=STRING,SEGMENT8=STRING,SEGMENT9=STRING,SEGMENT10=STRING,SEGMENT11=STRING,SEGMENT12=STRING,SEGMENT13=STRING,SEGMENT14=STRING,SEGMENT15=STRING,SEGMENT16=STRING,SEGMENT17=STRING,SEGMENT18=STRING,SEGMENT19=STRING,SEGMENT20=STRING,ATTRIBUTE_CATEGORY=STRING,ATTRIBUTE1=STRING,ATTRIBUTE2=STRING,ATTRIBUTE3=STRING,ATTRIBUTE4=STRING,ATTRIBUTE5=STRING,ATTRIBUTE6=STRING,ATTRIBUTE7=STRING,ATTRIBUTE8=STRING,ATTRIBUTE9=STRING,ATTRIBUTE10=STRING,ATTRIBUTE11=STRING,ATTRIBUTE12=STRING,ATTRIBUTE13=STRING,ATTRIBUTE14=STRING,ATTRIBUTE15=STRING,PURCHASING_ITEM_FLAG=STRING,SHIPPABLE_ITEM_FLAG=STRING,CUSTOMER_ORDER_FLAG=STRING,INTERNAL_ORDER_FLAG=STRING,SERVICE_ITEM_FLAG=STRING,INVENTORY_ITEM_FLAG=STRING,ENG_ITEM_FLAG=STRING,INVENTORY_ASSET_FLAG=STRING,PURCHASING_ENABLED_FLAG=STRING,CUSTOMER_ORDER_ENABLED_FLAG=STRING,INTERNAL_ORDER_ENABLED_FLAG=STRING,SO_TRANSACTIONS_FLAG=STRING,MTL_TRANSACTIONS_ENABLED_FLAG=STRING,STOCK_ENABLED_FLAG=STRING,BOM_ENABLED_FLAG=STRING,BUILD_IN_WIP_FLAG=STRING,REVISION_QTY_CONTROL_CODE=BIGINT,ITEM_CATALOG_GROUP_ID=BIGINT,CATALOG_STATUS_FLAG=STRING,RETURNABLE_FLAG=STRING,DEFAULT_SHIPPING_ORG=BIGINT,COLLATERAL_FLAG=STRING,TAXABLE_FLAG=STRING,QTY_RCV_EXCEPTION_CODE=STRING,ALLOW_ITEM_DESC_UPDATE_FLAG=STRING,INSPECTION_REQUIRED_FLAG=STRING,RECEIPT_REQUIRED_FLAG=STRING,MARKET_PRICE=BIGINT,HAZARD_CLASS_ID=BIGINT,RFQ_REQUIRED_FLAG=STRING,QTY_RCV_TOLERANCE=BIGINT,LIST_PRICE_PER_UNIT=BIGINT,UN_NUMBER_ID=BIGINT,PRICE_TOLERANCE_PERCENT=BIGINT,ASSET_CATEGORY_ID=BIGINT,ROUNDING_FACTOR=BIGINT,UNIT_OF_ISSUE=STRING,ENFORCE_SHIP_TO_LOCATION_CODE=STRING,ALLOW_SUBSTITUTE_RECEIPTS_FLAG=STRING,ALLOW_UNORDERED_RECEIPTS_FLAG=STRING,ALLOW_EXPRESS_DELIVERY_FLAG=STRING,DAYS_EARLY_RECEIPT_ALLOWED=BIGINT,DAYS_LATE_RECEIPT_ALLOWED=BIGINT,RECEIPT_DAYS_EXCEPTION_CODE=STRING,RECEIVING_ROUTING_ID=BIGINT,INVOICE_CLOSE_TOLERANCE=BIGINT,RECEIVE_CLOSE_TOLERANCE=BIGINT,AUTO_LOT_ALPHA_PREFIX=STRING,START_AUTO_LOT_NUMBER=STRING,LOT_CONTROL_CODE=BIGINT,SHELF_LIFE_CODE=BIGINT,SHELF_LIFE_DAYS=BIGINT,SERIAL_NUMBER_CONTROL_CODE=BIGINT,START_AUTO_SERIAL_NUMBER=STRING,AUTO_SERIAL_ALPHA_PREFIX=STRING,SOURCE_TYPE=BIGINT,SOURCE_ORGANIZATION_ID=BIGINT,SOURCE_SUBINVENTORY=STRING,EXPENSE_ACCOUNT=BIGINT,ENCUMBRANCE_ACCOUNT=BIGINT,RESTRICT_SUBINVENTORIES_CODE=BIGINT,UNIT_WEIGHT=BIGINT,WEIGHT_UOM_CODE=STRING,VOLUME_UOM_CODE=STRING,UNIT_VOLUME=BIGINT,RESTRICT_LOCATORS_CODE=BIGINT,LOCATION_CONTROL_CODE=BIGINT,SHRINKAGE_RATE=BIGINT,ACCEPTABLE_EARLY_DAYS=BIGINT,PLANNING_TIME_FENCE_CODE=BIGINT,DEMAND_TIME_FENCE_CODE=BIGINT,LEAD_TIME_LOT_SIZE=BIGINT,STD_LOT_SIZE=BIGINT,CUM_MANUFACTURING_LEAD_TIME=BIGINT,OVERRUN_PERCENTAGE=BIGINT,MRP_CALCULATE_ATP_FLAG=STRING,ACCEPTABLE_RATE_INCREASE=BIGINT,ACCEPTABLE_RATE_DECREASE=BIGINT,CUMULATIVE_TOTAL_LEAD_TIME=BIGINT,PLANNING_TIME_FENCE_DAYS=BIGINT,DEMAND_TIME_FENCE_DAYS=BIGINT,END_ASSEMBLY_PEGGING_FLAG=STRING,REPETITIVE_PLANNING_FLAG=STRING,PLANNING_EXCEPTION_SET=STRING,BOM_ITEM_TYPE=BIGINT,PICK_COMPONENTS_FLAG=STRING,REPLENISH_TO_ORDER_FLAG=STRING,BASE_ITEM_ID=BIGINT,ATP_COMPONENTS_FLAG=STRING,ATP_FLAG=STRING,FIXED_LEAD_TIME=BIGINT,VARIABLE_LEAD_TIME=BIGINT,WIP_SUPPLY_LOCATOR_ID=BIGINT,WIP_SUPPLY_TYPE=BIGINT,WIP_SUPPLY_SUBINVENTORY=STRING,PRIMARY_UOM_CODE=STRING,PRIMARY_UNIT_OF_MEASURE=STRING,ALLOWED_UNITS_LOOKUP_CODE=BIGINT,COST_OF_SALES_ACCOUNT=BIGINT,SALES_ACCOUNT=BIGINT,DEFAULT_INCLUDE_IN_ROLLUP_FLAG=STRING,INVENTORY_ITEM_STATUS_CODE=STRING,INVENTORY_PLANNING_CODE=BIGINT,PLANNER_CODE=STRING,PLANNING_MAKE_BUY_CODE=BIGINT,FIXED_LOT_MULTIPLIER=BIGINT,ROUNDING_CONTROL_TYPE=BIGINT,CARRYING_COST=BIGINT,POSTPROCESSING_LEAD_TIME=BIGINT,PREPROCESSING_LEAD_TIME=BIGINT,FULL_LEAD_TIME=BIGINT,ORDER_COST=BIGINT,MRP_SAFETY_STOCK_PERCENT=BIGINT,MRP_SAFETY_STOCK_CODE=BIGINT,MIN_MINMAX_QUANTITY=BIGINT,MAX_MINMAX_QUANTITY=BIGINT,MINIMUM_ORDER_QUANTITY=BIGINT,FIXED_ORDER_QUANTITY=BIGINT,FIXED_DAYS_SUPPLY=BIGINT,MAXIMUM_ORDER_QUANTITY=BIGINT,ATP_RULE_ID=BIGINT,PICKING_RULE_ID=BIGINT,RESERVABLE_TYPE=BIGINT,POSITIVE_MEASUREMENT_ERROR=BIGINT,NEGATIVE_MEASUREMENT_ERROR=BIGINT,ENGINEERING_ECN_CODE=STRING,ENGINEERING_ITEM_ID=BIGINT,ENGINEERING_DATE=TIMESTAMP,SERVICE_STARTING_DELAY=BIGINT,VENDOR_WARRANTY_FLAG=STRING,SERVICEABLE_COMPONENT_FLAG=STRING,SERVICEABLE_PRODUCT_FLAG=STRING,BASE_WARRANTY_SERVICE_ID=BIGINT,PAYMENT_TERMS_ID=BIGINT,PREVENTIVE_MAINTENANCE_FLAG=STRING,PRIMARY_SPECIALIST_ID=BIGINT,SECONDARY_SPECIALIST_ID=BIGINT,SERVICEABLE_ITEM_CLASS_ID=BIGINT,TIME_BILLABLE_FLAG=STRING,MATERIAL_BILLABLE_FLAG=STRING,EXPENSE_BILLABLE_FLAG=STRING,PRORATE_SERVICE_FLAG=STRING,COVERAGE_SCHEDULE_ID=BIGINT,SERVICE_DURATION_PERIOD_CODE=STRING,SERVICE_DURATION=BIGINT,WARRANTY_VENDOR_ID=BIGINT,MAX_WARRANTY_AMOUNT=BIGINT,RESPONSE_TIME_PERIOD_CODE=STRING,RESPONSE_TIME_VALUE=BIGINT,NEW_REVISION_CODE=STRING,INVOICEABLE_ITEM_FLAG=STRING,TAX_CODE=STRING,INVOICE_ENABLED_FLAG=STRING,MUST_USE_APPROVED_VENDOR_FLAG=STRING,REQUEST_ID=BIGINT,PROGRAM_APPLICATION_ID=BIGINT,PROGRAM_ID=BIGINT,PROGRAM_UPDATE_DATE=TIMESTAMP,OUTSIDE_OPERATION_FLAG=STRING,OUTSIDE_OPERATION_UOM_TYPE=STRING,SAFETY_STOCK_BUCKET_DAYS=BIGINT,AUTO_REDUCE_MPS=BIGINT,COSTING_ENABLED_FLAG=STRING,AUTO_CREATED_CONFIG_FLAG=STRING,CYCLE_COUNT_ENABLED_FLAG=STRING,ITEM_TYPE=STRING,MODEL_CONFIG_CLAUSE_NAME=STRING,SHIP_MODEL_COMPLETE_FLAG=STRING,MRP_PLANNING_CODE=BIGINT,RETURN_INSPECTION_REQUIREMENT=BIGINT,ATO_FORECAST_CONTROL=BIGINT,RELEASE_TIME_FENCE_CODE=BIGINT,RELEASE_TIME_FENCE_DAYS=BIGINT,CONTAINER_ITEM_FLAG=STRING,VEHICLE_ITEM_FLAG=STRING,MAXIMUM_LOAD_WEIGHT=BIGINT,MINIMUM_FILL_PERCENT=BIGINT,CONTAINER_TYPE_CODE=STRING,INTERNAL_VOLUME=BIGINT,WH_UPDATE_DATE=TIMESTAMP,PRODUCT_FAMILY_ITEM_ID=BIGINT,GLOBAL_ATTRIBUTE_CATEGORY=STRING,GLOBAL_ATTRIBUTE1=STRING,GLOBAL_ATTRIBUTE2=STRING,GLOBAL_ATTRIBUTE3=STRING,GLOBAL_ATTRIBUTE4=STRING,GLOBAL_ATTRIBUTE5=STRING,GLOBAL_ATTRIBUTE6=STRING,GLOBAL_ATTRIBUTE7=STRING,GLOBAL_ATTRIBUTE8=STRING,GLOBAL_ATTRIBUTE9=STRING,GLOBAL_ATTRIBUTE10=STRING,PURCHASING_TAX_CODE=STRING,OVERCOMPLETION_TOLERANCE_TYPE=BIGINT,OVERCOMPLETION_TOLERANCE_VALUE=BIGINT,EFFECTIVITY_CONTROL=BIGINT,CHECK_SHORTAGES_FLAG=STRING,OVER_SHIPMENT_TOLERANCE=BIGINT,UNDER_SHIPMENT_TOLERANCE=BIGINT,OVER_RETURN_TOLERANCE=BIGINT,UNDER_RETURN_TOLERANCE=BIGINT,EQUIPMENT_TYPE=BIGINT,RECOVERED_PART_DISP_CODE=STRING,DEFECT_TRACKING_ON_FLAG=STRING,USAGE_ITEM_FLAG=STRING,EVENT_FLAG=STRING,ELECTRONIC_FLAG=STRING,DOWNLOADABLE_FLAG=STRING,VOL_DISCOUNT_EXEMPT_FLAG=STRING,COUPON_EXEMPT_FLAG=STRING,COMMS_NL_TRACKABLE_FLAG=STRING,ASSET_CREATION_CODE=STRING,COMMS_ACTIVATION_REQD_FLAG=STRING,ORDERABLE_ON_WEB_FLAG=STRING,BACK_ORDERABLE_FLAG=STRING,WEB_STATUS=STRING,INDIVISIBLE_FLAG=STRING,DIMENSION_UOM_CODE=STRING,UNIT_LENGTH=BIGINT,UNIT_WIDTH=BIGINT,UNIT_HEIGHT=BIGINT,BULK_PICKED_FLAG=STRING,LOT_STATUS_ENABLED=STRING,DEFAULT_LOT_STATUS_ID=BIGINT,SERIAL_STATUS_ENABLED=STRING,DEFAULT_SERIAL_STATUS_ID=BIGINT,LOT_SPLIT_ENABLED=STRING,LOT_MERGE_ENABLED=STRING,INVENTORY_CARRY_PENALTY=BIGINT,OPERATION_SLACK_PENALTY=BIGINT,FINANCING_ALLOWED_FLAG=STRING,EAM_ITEM_TYPE=BIGINT,EAM_ACTIVITY_TYPE_CODE=STRING,EAM_ACTIVITY_CAUSE_CODE=STRING,EAM_ACT_NOTIFICATION_FLAG=STRING,EAM_ACT_SHUTDOWN_STATUS=STRING,DUAL_UOM_CONTROL=BIGINT,SECONDARY_UOM_CODE=STRING,DUAL_UOM_DEVIATION_HIGH=BIGINT,DUAL_UOM_DEVIATION_LOW=BIGINT,CONTRACT_ITEM_TYPE_CODE=STRING,SUBSCRIPTION_DEPEND_FLAG=STRING,SERV_REQ_ENABLED_CODE=STRING,SERV_BILLING_ENABLED_FLAG=STRING,SERV_IMPORTANCE_LEVEL=BIGINT,PLANNED_INV_POINT_FLAG=STRING,LOT_TRANSLATE_ENABLED=STRING,DEFAULT_SO_SOURCE_TYPE=STRING,CREATE_SUPPLY_FLAG=STRING,SUBSTITUTION_WINDOW_CODE=BIGINT,SUBSTITUTION_WINDOW_DAYS=BIGINT,IB_ITEM_INSTANCE_CLASS=STRING,CONFIG_MODEL_TYPE=STRING,LOT_SUBSTITUTION_ENABLED=STRING,MINIMUM_LICENSE_QUANTITY=BIGINT,EAM_ACTIVITY_SOURCE_CODE=STRING,LIFECYCLE_ID=BIGINT,CURRENT_PHASE_ID=BIGINT,OBJECT_VERSION_NUMBER=BIGINT,CDB_DATA_SOURCE=STRING,CDB_ENQUEUE_TIME=TIMESTAMP,CDB_DEQUEUE_TIME=TIMESTAMP,CDB_ENQUEUE_SEQ=BIGINT --boundary-query 'select (select min(INVENTORY_ITEM_ID) from MTL_SYSTEM_ITEMS_B) as minid ,(select max(INVENTORY_ITEM_ID) from MTL_SYSTEM_ITEMS_B) as maxid from dual' " >> /apps/pentaho_nfs/installbase/input/poc/logs/IB_logs.log 2>&1
But, the command fails executing with a syntax error as the command seems to be split at the select query which is not being identified by sqoop cli. Whereas, when i run the same command directly on the cli it works like a charm.
Here, is my java code which creates a string array from the command and passes it to the ProcessBuilder object.
public void run() {
ProcessBuilder processbuilder = new ProcessBuilder(command);
try {
Process process = processbuilder.inheritIO().start();
process.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String readline;
while ((readline = reader.readLine()) != null) {
LOGGER.info(readline);
}
} catch (Exception e) {
LOGGER.error(e.getMessage());
}
}
static String[] command = null;
static String SQOOP_XXCCS_DS_SAHDR_CORE = ReadProperties.getInstance().getProperty("SQOOP_XXCCS_DS_SAHDR_CORE");
static String SQOOP_XXCCS_DS_CVDPRDLINE_DETAIL = ReadProperties.getInstance()
.getProperty("SQOOP_XXCCS_DS_CVDPRDLINE_DETAIL");
static String SQOOP_XXCCS_DS_INSTANCE_DETAIL = ReadProperties.getInstance()
.getProperty("SQOOP_XXCCS_DS_INSTANCE_DETAIL");
static String SQOOP_XXCCS_SCDC_PRODUCT_PROFILE = ReadProperties.getInstance()
.getProperty("SQOOP_XXCCS_SCDC_PRODUCT_PROFILE");
static String SQOOP_MTL_SYSTEM_ITEMS_B = ReadProperties.getInstance().getProperty("SQOOP_MTL_SYSTEM_ITEMS_B");
public static void main(String[] args) {
ThreadPoolExecutor executors = (ThreadPoolExecutor) Executors.newFixedThreadPool(5);
List<String> getlist = getList();
for (Iterator<String> itr = getlist.iterator(); itr.hasNext();) {
String element = (String) itr.next();
LOGGER.info(element);
command = element.split(" ");
LOGGER.info("Executing the command as below \n");
LOGGER.info(command);
ParallelExecutor pe = new ParallelExecutor(command);
executors.execute(pe);
}
executors.shutdown();
}
public static List<String> getList() {
List<String> commandlist = new ArrayList<String>();
commandlist.add(SQOOP_XXCCS_DS_SAHDR_CORE);
commandlist.add(SQOOP_XXCCS_DS_CVDPRDLINE_DETAIL);
commandlist.add(SQOOP_XXCCS_DS_INSTANCE_DETAIL);
commandlist.add(SQOOP_XXCCS_SCDC_PRODUCT_PROFILE);
commandlist.add(SQOOP_MTL_SYSTEM_ITEMS_B);
return commandlist;
}
Is there an elegant way i can pass the command to the processbuilder avoiding the syntactical errors. Need your valuable suggestions.
Stack Trace 1:
log4j:WARN No appenders could be found for logger (com.cisco.parallelexecutor.ParallelExecutor).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "main" java.io.IOException: Cannot run program "ssh hddev-c01-edge-02 "sqoop import -D mapred.child.java.opts='-Djava.security.egd=file:/dev/../dev/urandom' --connect 'jdbc:oracle:thin:#(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=dbs-dev-vm-2009.cisco.com)(PORT=1533))(CONNECT_DATA=(SERVICE_NAME=SDADEV.CISCO.COM)(Server=Dedicated)))' --username XXCTS_NITA_U --password OBCK9I2Q --query "select CONTRACT_ID,CONTRACT_NUMBER,CONTRACT_STS_CODE,CONTRACT_STATUS,SERVICE_LINE_ID,SERVICE_LINE_NAME,SERVICE_LINE_STS_CODE,SERVICE_LINE_STATUS,SERVICE_LINE_NUMBER,HDR_CUST_ACCOUNT_ID,HDR_CUST_ACCOUNT_NUMBER,HDR_PARTY_ID,HDR_CUSTOMER_NAME,LINE_CUST_ACCOUNT_ID,LINE_CUST_ACCOUNT_NUMBER,LINE_PARTY_ID,LINE_CUSTOMER_NAME,BILL_TO_SITE_USE_ID,BILL_TO_SITE_USE_NAME,BILL_TO_SITE_USE_STS,BILL_TO_CUST_ACCT_ID,BILL_TO_CUST_ACCT_NUMBER,BILL_TO_CUST_ACCT_STS,BILL_TO_CUST_ACCT_SITE_ID,BILL_TO_CUST_ACCT_SITE_STS,BILL_TO_PARTY_ID,BILL_TO_PARTY_NUMBER,BILL_TO_CUSTOMER_NAME,BILL_TO_PARTY_STS,BILL_TO_PARTY_SITE_ID,BILL_TO_PARTY_SITE_STS,BILL_TO_LOCATION_ID,BILL_TO_COUNTRY,BILL_TO_STATE_PROV,BILL_TO_CITY,BILL_TO_POSTAL_CODE,COVERAGE_TEMPLATE_ID,COVERAGE_TEMPLATE_NAME,COVERAGE_TEMPLATE_DESC,COVERAGE_BEGIN_DATE,COVERAGE_END_DATE,SERVICE_SALES_REP_USR_ID,SERVICE_SALES_REP_USR_NAME,SERVICE_LINE_INVENTORY_ITEM_ID,BILLTO_CSC_ID,BILLTO_CSC_NAME,BILLTO_GU_ID,BILLTO_GU_NAME,BILL_TO_CUSTOMER_SALES_CHANNEL,CURRENCY_CODE,CONTRACT_LIST_AMT,CONTRACT_NET_AMT,USD_CONTRACT_LIST_AMT,USD_CONTRACT_NET_AMT,ACCOUNT_TEAM,RENEWAL_SSR,RENEWAL_TEAM,SALES_REGION,ADVANCE_CONTRACT_FLAG,EARLIEST_END_DATE,SERVICE_LINE_TERMINATED_DATE,SVC_LINE_TERMINATION_REASON,CONTRACT_TERMINATED_DATE,USD_CONV_RATE,PRICE_TYPE,NET_VALUE,COTERM_DATE,MARKETING_PROGRAM,MASTER_AGREEMENT_END_DATE,DISCOUNT_PERCENT,PRORATE_FLAG,RGP_ID,CREATION_DATE,CREATED_BY,LAST_UPDATE_DATE,LAST_UPDATED_BY,LAST_UPDATED_LOGIN,REQUEST_ID,PROGRAM_UPDATE_DATE,PROGRAM_APPLICATION_ID,PROGRAM_ID,ATTRIBUTE_CATEGORY,ATTRIBUTE1,ATTRIBUTE2,ATTRIBUTE3,ATTRIBUTE4,ATTRIBUTE5,ATTRIBUTE6,ATTRIBUTE7,ATTRIBUTE8,ATTRIBUTE9,ATTRIBUTE10,ATTRIBUTE11,ATTRIBUTE12,ATTRIBUTE13,ATTRIBUTE14,ATTRIBUTE15,ATTRIBUTE16,ATTRIBUTE17,ATTRIBUTE18,ATTRIBUTE19,ATTRIBUTE20,ACCOUNT_SSR,SHELL_CONTRACT_FLAG,CONTRACT_START_DATE,CONTRACT_END_DATE from XXCCS_DS_SAHDR_CORE where \$CONDITIONS " --split-by CONTRACT_NUMBER -m 4 --null-string '\\N' --null-non-string '\\N' --hive-delims-replacement '<EOL>' --boundary-query 'select (select min(CONTRACT_NUMBER) from XXCCS_DS_SAHDR_CORE) as minid ,(select max(CONTRACT_NUMBER) from XXCCS_DS_SAHDR_CORE) as maxid from dual' --target-dir /app/dev/SmartAnalytics/sqoop_temp//XXCCS_DS_SAHDR_CORE --hive-import --hive-overwrite --hive-table installbase.XXCCS_DS_SAHDR_CORE --map-column-hive CONTRACT_ID=BIGINT,SERVICE_LINE_ID=BIGINT,HDR_CUST_ACCOUNT_ID=BIGINT,HDR_PARTY_ID=BIGINT,LINE_CUST_ACCOUNT_ID=BIGINT,LINE_PARTY_ID=BIGINT,BILL_TO_SITE_USE_ID=BIGINT,BILL_TO_CUST_ACCT_ID=BIGINT,BILL_TO_CUST_ACCT_SITE_ID=BIGINT,BILL_TO_PARTY_ID=BIGINT,BILL_TO_PARTY_SITE_ID=BIGINT,BILL_TO_LOCATION_ID=BIGINT,COVERAGE_TEMPLATE_ID=BIGINT,COVERAGE_BEGIN_DATE=TIMESTAMP,COVERAGE_END_DATE=TIMESTAMP,SERVICE_LINE_INVENTORY_ITEM_ID=BIGINT,BILLTO_CSC_ID=BIGINT,BILLTO_GU_ID=BIGINT,CONTRACT_LIST_AMT=BIGINT,CONTRACT_NET_AMT=BIGINT,USD_CONTRACT_LIST_AMT=BIGINT,USD_CONTRACT_NET_AMT=BIGINT,EARLIEST_END_DATE=TIMESTAMP,SERVICE_LINE_TERMINATED_DATE=TIMESTAMP,CONTRACT_TERMINATED_DATE=TIMESTAMP,USD_CONV_RATE=BIGINT,NET_VALUE=BIGINT,MASTER_AGREEMENT_END_DATE=TIMESTAMP,DISCOUNT_PERCENT=BIGINT,PRORATE_FLAG=STRING,RGP_ID=BIGINT,CREATION_DATE=TIMESTAMP,CREATED_BY=BIGINT,LAST_UPDATE_DATE=TIMESTAMP,LAST_UPDATED_BY=BIGINT,LAST_UPDATED_LOGIN=BIGINT,REQUEST_ID=BIGINT,PROGRAM_UPDATE_DATE=TIMESTAMP,PROGRAM_APPLICATION_ID=BIGINT,PROGRAM_ID=BIGINT,ATTRIBUTE_CATEGORY=STRING,ATTRIBUTE1=STRING,ATTRIBUTE2=STRING,ATTRIBUTE3=STRING,ATTRIBUTE4=STRING,ATTRIBUTE5=STRING,ATTRIBUTE6=STRING,ATTRIBUTE7=STRING,ATTRIBUTE8=STRING,ATTRIBUTE9=STRING,ATTRIBUTE10=STRING,ATTRIBUTE11=STRING,ATTRIBUTE12=STRING,ATTRIBUTE13=STRING,ATTRIBUTE14=STRING,ATTRIBUTE15=STRING,ATTRIBUTE16=STRING,ATTRIBUTE17=STRING,ATTRIBUTE18=STRING,ATTRIBUTE19=STRING,ATTRIBUTE20=STRING,ACCOUNT_SSR=STRING,SHELL_CONTRACT_FLAG=STRING,CONTRACT_START_DATE=TIMESTAMP,CONTRACT_END_DATE=TIMESTAMP" >> /apps/pentaho_nfs/installbase/input/poc/logs/IB_logs.log 2>&1 ": error=36, File name too long
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1047)
at com.cisco.parallelexecutor.ParallelExecutor.main(ParallelExecutor.java:35)
Caused by: java.io.IOException: error=36, File name too long
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:186)
at java.lang.ProcessImpl.start(ProcessImpl.java:130)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1028)
... 1 more
StackTrace 2:
Warning: /usr/lib/hcatalog does not exist! HCatalog jobs will fail.
Please set $HCAT_HOME to the root of your HCatalog installation.
--table or --query is required for import. (Or use sqoop import-all-tables.)
Try --help for usage instructions.
usage: sqoop import [GENERIC-ARGS] [TOOL-ARGS]
Common arguments:
--connect <jdbc-uri> Specify JDBC connect
string
--connection-manager <class-name> Specify connection manager
class name
--connection-param-file <properties-file> Specify connection
parameters file
--driver <class-name> Manually specify JDBC
driver class to use
--hadoop-home <hdir> Override
$HADOOP_MAPRED_HOME_ARG
--hadoop-mapred-home <dir> Override
$HADOOP_MAPRED_HOME_ARG
--help Print usage instructions
-P Read password from console
--password <password> Set authentication
password
--password-file <password-file> Set authentication
password file path
--username <username> Set authentication
username
--verbose Print more information
while working
Import control arguments:
--append Imports data
in append
mode
--as-avrodatafile Imports data
to Avro data
files
--as-sequencefile Imports data
to
SequenceFile
s
--as-textfile Imports data
as plain
text
(default)
--boundary-query <statement> Set boundary
query for
retrieving
max and min
value of the
primary key
--columns <col,col,col...> Columns to
import from
table
--compression-codec <codec> Compression
codec to use
for import
--delete-target-dir Imports data
in delete
mode
--direct Use direct
import fast
The issue is resolved after making the following changes in the code.
String[] command = { "ssh", "hddev-chost-01-01", "\"" + element + "\"" };
I am passing the command as a string array as per the ProcessBuilder documentation. Instead of sending the whole command as an array i am substituting the below command as as string "element".
String element = "sqoop import -D oraoop.disabled=true -D mapred.child.java.opts='\-Djava.security.egd=file:/dev/../dev/urandom' --connect 'jdbc:oracle:thin:#(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=maildude.com)(PORT=1533))(CONNECT_DATA=(SERVICE_NAME=SDA.COM)(Server=Dedicated)))' --username user --password pass --query \"select INVENTORY_ITEM_ID,ORGANIZATION_ID,LAST_UPDATE_DATE,LAST_UPDATED_BY,CREATION_DATE,CREATED_BY,LAST_UPDATE_LOGIN,SUMMARY_FLAG,ENABLED_FLAG,START_DATE_ACTIVE,END_DATE_ACTIVE,DESCRIPTION,BUYER_ID,ACCOUNTING_RULE_ID,INVOICING_RULE_ID,SEGMENT1,SEGMENT2,SEGMENT3,SEGMENT4,SEGMENT5,SEGMENT6,SEGMENT7,SEGMENT8,SEGMENT9,SEGMENT10,SEGMENT11,SEGMENT12,SEGMENT13,SEGMENT14,SEGMENT15,SEGMENT16,SEGMENT17,SEGMENT18,SEGMENT19,SEGMENT20,ATTRIBUTE_CATEGORY,ATTRIBUTE1,ATTRIBUTE2,ATTRIBUTE3,ATTRIBUTE4,ATTRIBUTE5,ATTRIBUTE6,ATTRIBUTE7,ATTRIBUTE8,ATTRIBUTE9,ATTRIBUTE10,ATTRIBUTE11,ATTRIBUTE12,ATTRIBUTE13,ATTRIBUTE14,ATTRIBUTE15,PURCHASING_ITEM_FLAG,SHIPPABLE_ITEM_FLAG,CUSTOMER_ORDER_FLAG,INTERNAL_ORDER_FLAG,SERVICE_ITEM_FLAG,INVENTORY_ITEM_FLAG,ENG_ITEM_FLAG,INVENTORY_ASSET_FLAG,PURCHASING_ENABLED_FLAG,CUSTOMER_ORDER_ENABLED_FLAG,INTERNAL_ORDER_ENABLED_FLAG,SO_TRANSACTIONS_FLAG,MTL_TRANSACTIONS_ENABLED_FLAG,STOCK_ENABLED_FLAG,BOM_ENABLED_FLAG,BUILD_IN_WIP_FLAG,REVISION_QTY_CONTROL_CODE,ITEM_CATALOG_GROUP_ID,CATALOG_STATUS_FLAG,RETURNABLE_FLAG,DEFAULT_SHIPPING_ORG,COLLATERAL_FLAG,TAXABLE_FLAG,QTY_RCV_EXCEPTION_CODE,ALLOW_ITEM_DESC_UPDATE_FLAG,INSPECTION_REQUIRED_FLAG,RECEIPT_REQUIRED_FLAG,MARKET_PRICE,HAZARD_CLASS_ID,RFQ_REQUIRED_FLAG,QTY_RCV_TOLERANCE,LIST_PRICE_PER_UNIT,UN_NUMBER_ID,PRICE_TOLERANCE_PERCENT,ASSET_CATEGORY_ID,ROUNDING_FACTOR,UNIT_OF_ISSUE,ENFORCE_SHIP_TO_LOCATION_CODE,ALLOW_SUBSTITUTE_RECEIPTS_FLAG,ALLOW_UNORDERED_RECEIPTS_FLAG,ALLOW_EXPRESS_DELIVERY_FLAG,DAYS_EARLY_RECEIPT_ALLOWED,DAYS_LATE_RECEIPT_ALLOWED,RECEIPT_DAYS_EXCEPTION_CODE,RECEIVING_ROUTING_ID,INVOICE_CLOSE_TOLERANCE,RECEIVE_CLOSE_TOLERANCE,AUTO_LOT_ALPHA_PREFIX,START_AUTO_LOT_NUMBER,LOT_CONTROL_CODE,SHELF_LIFE_CODE,SHELF_LIFE_DAYS,SERIAL_NUMBER_CONTROL_CODE,START_AUTO_SERIAL_NUMBER,AUTO_SERIAL_ALPHA_PREFIX,SOURCE_TYPE,SOURCE_ORGANIZATION_ID,SOURCE_SUBINVENTORY,EXPENSE_ACCOUNT,ENCUMBRANCE_ACCOUNT,RESTRICT_SUBINVENTORIES_CODE,UNIT_WEIGHT,WEIGHT_UOM_CODE,VOLUME_UOM_CODE,UNIT_VOLUME,RESTRICT_LOCATORS_CODE,LOCATION_CONTROL_CODE,SHRINKAGE_RATE,ACCEPTABLE_EARLY_DAYS,PLANNING_TIME_FENCE_CODE,DEMAND_TIME_FENCE_CODE,LEAD_TIME_LOT_SIZE,STD_LOT_SIZE,CUM_MANUFACTURING_LEAD_TIME,OVERRUN_PERCENTAGE,MRP_CALCULATE_ATP_FLAG,ACCEPTABLE_RATE_INCREASE,ACCEPTABLE_RATE_DECREASE,CUMULATIVE_TOTAL_LEAD_TIME,PLANNING_TIME_FENCE_DAYS,DEMAND_TIME_FENCE_DAYS,END_ASSEMBLY_PEGGING_FLAG,REPETITIVE_PLANNING_FLAG,PLANNING_EXCEPTION_SET,BOM_ITEM_TYPE,PICK_COMPONENTS_FLAG,REPLENISH_TO_ORDER_FLAG,BASE_ITEM_ID,ATP_COMPONENTS_FLAG,ATP_FLAG,FIXED_LEAD_TIME,VARIABLE_LEAD_TIME,WIP_SUPPLY_LOCATOR_ID,WIP_SUPPLY_TYPE,WIP_SUPPLY_SUBINVENTORY,PRIMARY_UOM_CODE,PRIMARY_UNIT_OF_MEASURE,ALLOWED_UNITS_LOOKUP_CODE,COST_OF_SALES_ACCOUNT,SALES_ACCOUNT,DEFAULT_INCLUDE_IN_ROLLUP_FLAG,INVENTORY_ITEM_STATUS_CODE,INVENTORY_PLANNING_CODE,PLANNER_CODE,PLANNING_MAKE_BUY_CODE,FIXED_LOT_MULTIPLIER,ROUNDING_CONTROL_TYPE,CARRYING_COST,POSTPROCESSING_LEAD_TIME,PREPROCESSING_LEAD_TIME,FULL_LEAD_TIME,ORDER_COST,MRP_SAFETY_STOCK_PERCENT,MRP_SAFETY_STOCK_CODE,MIN_MINMAX_QUANTITY,MAX_MINMAX_QUANTITY,MINIMUM_ORDER_QUANTITY,FIXED_ORDER_QUANTITY,FIXED_DAYS_SUPPLY,MAXIMUM_ORDER_QUANTITY,ATP_RULE_ID,PICKING_RULE_ID,RESERVABLE_TYPE,POSITIVE_MEASUREMENT_ERROR,NEGATIVE_MEASUREMENT_ERROR,ENGINEERING_ECN_CODE,ENGINEERING_ITEM_ID,ENGINEERING_DATE,SERVICE_STARTING_DELAY,VENDOR_WARRANTY_FLAG,SERVICEABLE_COMPONENT_FLAG,SERVICEABLE_PRODUCT_FLAG,BASE_WARRANTY_SERVICE_ID,PAYMENT_TERMS_ID,PREVENTIVE_MAINTENANCE_FLAG,PRIMARY_SPECIALIST_ID,SECONDARY_SPECIALIST_ID,SERVICEABLE_ITEM_CLASS_ID,TIME_BILLABLE_FLAG,MATERIAL_BILLABLE_FLAG,EXPENSE_BILLABLE_FLAG,PRORATE_SERVICE_FLAG,COVERAGE_SCHEDULE_ID,SERVICE_DURATION_PERIOD_CODE,SERVICE_DURATION,WARRANTY_VENDOR_ID,MAX_WARRANTY_AMOUNT,RESPONSE_TIME_PERIOD_CODE,RESPONSE_TIME_VALUE,NEW_REVISION_CODE,INVOICEABLE_ITEM_FLAG,TAX_CODE,INVOICE_ENABLED_FLAG,MUST_USE_APPROVED_VENDOR_FLAG,REQUEST_ID,PROGRAM_APPLICATION_ID,PROGRAM_ID,PROGRAM_UPDATE_DATE,OUTSIDE_OPERATION_FLAG,OUTSIDE_OPERATION_UOM_TYPE,SAFETY_STOCK_BUCKET_DAYS,AUTO_REDUCE_MPS,COSTING_ENABLED_FLAG,AUTO_CREATED_CONFIG_FLAG,CYCLE_COUNT_ENABLED_FLAG,ITEM_TYPE,MODEL_CONFIG_CLAUSE_NAME,SHIP_MODEL_COMPLETE_FLAG,MRP_PLANNING_CODE,RETURN_INSPECTION_REQUIREMENT,ATO_FORECAST_CONTROL,RELEASE_TIME_FENCE_CODE,RELEASE_TIME_FENCE_DAYS,CONTAINER_ITEM_FLAG,VEHICLE_ITEM_FLAG,MAXIMUM_LOAD_WEIGHT,MINIMUM_FILL_PERCENT,CONTAINER_TYPE_CODE,INTERNAL_VOLUME,WH_UPDATE_DATE,PRODUCT_FAMILY_ITEM_ID,GLOBAL_ATTRIBUTE_CATEGORY,GLOBAL_ATTRIBUTE1,GLOBAL_ATTRIBUTE2,GLOBAL_ATTRIBUTE3,GLOBAL_ATTRIBUTE4,GLOBAL_ATTRIBUTE5,GLOBAL_ATTRIBUTE6,GLOBAL_ATTRIBUTE7,GLOBAL_ATTRIBUTE8,GLOBAL_ATTRIBUTE9,GLOBAL_ATTRIBUTE10,PURCHASING_TAX_CODE,OVERCOMPLETION_TOLERANCE_TYPE,OVERCOMPLETION_TOLERANCE_VALUE,EFFECTIVITY_CONTROL,CHECK_SHORTAGES_FLAG,OVER_SHIPMENT_TOLERANCE,UNDER_SHIPMENT_TOLERANCE,OVER_RETURN_TOLERANCE,UNDER_RETURN_TOLERANCE,EQUIPMENT_TYPE,RECOVERED_PART_DISP_CODE,DEFECT_TRACKING_ON_FLAG,USAGE_ITEM_FLAG,EVENT_FLAG,ELECTRONIC_FLAG,DOWNLOADABLE_FLAG,VOL_DISCOUNT_EXEMPT_FLAG,COUPON_EXEMPT_FLAG,COMMS_NL_TRACKABLE_FLAG,ASSET_CREATION_CODE,COMMS_ACTIVATION_REQD_FLAG,ORDERABLE_ON_WEB_FLAG,BACK_ORDERABLE_FLAG,WEB_STATUS,INDIVISIBLE_FLAG,DIMENSION_UOM_CODE,UNIT_LENGTH,UNIT_WIDTH,UNIT_HEIGHT,BULK_PICKED_FLAG,LOT_STATUS_ENABLED,DEFAULT_LOT_STATUS_ID,SERIAL_STATUS_ENABLED,DEFAULT_SERIAL_STATUS_ID,LOT_SPLIT_ENABLED,LOT_MERGE_ENABLED,INVENTORY_CARRY_PENALTY,OPERATION_SLACK_PENALTY,FINANCING_ALLOWED_FLAG,EAM_ITEM_TYPE,EAM_ACTIVITY_TYPE_CODE,EAM_ACTIVITY_CAUSE_CODE,EAM_ACT_NOTIFICATION_FLAG,EAM_ACT_SHUTDOWN_STATUS,DUAL_UOM_CONTROL,SECONDARY_UOM_CODE,DUAL_UOM_DEVIATION_HIGH,DUAL_UOM_DEVIATION_LOW,CONTRACT_ITEM_TYPE_CODE,SUBSCRIPTION_DEPEND_FLAG,SERV_REQ_ENABLED_CODE,SERV_BILLING_ENABLED_FLAG,SERV_IMPORTANCE_LEVEL,PLANNED_INV_POINT_FLAG,LOT_TRANSLATE_ENABLED,DEFAULT_SO_SOURCE_TYPE,CREATE_SUPPLY_FLAG,SUBSTITUTION_WINDOW_CODE,SUBSTITUTION_WINDOW_DAYS,IB_ITEM_INSTANCE_CLASS,CONFIG_MODEL_TYPE,LOT_SUBSTITUTION_ENABLED,MINIMUM_LICENSE_QUANTITY,EAM_ACTIVITY_SOURCE_CODE,LIFECYCLE_ID,CURRENT_PHASE_ID,OBJECT_VERSION_NUMBER,CDB_DATA_SOURCE,CDB_ENQUEUE_TIME,CDB_DEQUEUE_TIME,CDB_ENQUEUE_SEQ from MTL_SYSTEM_ITEMS_B where \\\$CONDITIONS \" --target-dir /app/dev/SmartAnalytics/sqoop_temp//MTL_SYSTEM_ITEMS_B -m 4 --split-by INVENTORY_ITEM_ID --hive-import --hive-overwrite --hive-table installbase.MTL_SYSTEM_ITEMS_B --null-string '\\\\N' --null-non-string '\\\\N' --hive-delims-replacement '<EOL>' --map-column-hive INVENTORY_ITEM_ID=BIGINT,ORGANIZATION_ID=BIGINT,LAST_UPDATE_DATE=TIMESTAMP,LAST_UPDATED_BY=BIGINT,CREATION_DATE=TIMESTAMP,CREATED_BY=BIGINT,LAST_UPDATE_LOGIN=BIGINT,SUMMARY_FLAG=STRING,ENABLED_FLAG=STRING,START_DATE_ACTIVE=TIMESTAMP,END_DATE_ACTIVE=TIMESTAMP,DESCRIPTION=STRING,BUYER_ID=BIGINT,ACCOUNTING_RULE_ID=BIGINT,INVOICING_RULE_ID=BIGINT,SEGMENT1=STRING,SEGMENT2=STRING,SEGMENT3=STRING,SEGMENT4=STRING,SEGMENT5=STRING,SEGMENT6=STRING,SEGMENT7=STRING,SEGMENT8=STRING,SEGMENT9=STRING,SEGMENT10=STRING,SEGMENT11=STRING,SEGMENT12=STRING,SEGMENT13=STRING,SEGMENT14=STRING,SEGMENT15=STRING,SEGMENT16=STRING,SEGMENT17=STRING,SEGMENT18=STRING,SEGMENT19=STRING,SEGMENT20=STRING,ATTRIBUTE_CATEGORY=STRING,ATTRIBUTE1=STRING,ATTRIBUTE2=STRING,ATTRIBUTE3=STRING,ATTRIBUTE4=STRING,ATTRIBUTE5=STRING,ATTRIBUTE6=STRING,ATTRIBUTE7=STRING,ATTRIBUTE8=STRING,ATTRIBUTE9=STRING,ATTRIBUTE10=STRING,ATTRIBUTE11=STRING,ATTRIBUTE12=STRING,ATTRIBUTE13=STRING,ATTRIBUTE14=STRING,ATTRIBUTE15=STRING,PURCHASING_ITEM_FLAG=STRING,SHIPPABLE_ITEM_FLAG=STRING,CUSTOMER_ORDER_FLAG=STRING,INTERNAL_ORDER_FLAG=STRING,SERVICE_ITEM_FLAG=STRING,INVENTORY_ITEM_FLAG=STRING,ENG_ITEM_FLAG=STRING,INVENTORY_ASSET_FLAG=STRING,PURCHASING_ENABLED_FLAG=STRING,CUSTOMER_ORDER_ENABLED_FLAG=STRING,INTERNAL_ORDER_ENABLED_FLAG=STRING,SO_TRANSACTIONS_FLAG=STRING,MTL_TRANSACTIONS_ENABLED_FLAG=STRING,STOCK_ENABLED_FLAG=STRING,BOM_ENABLED_FLAG=STRING,BUILD_IN_WIP_FLAG=STRING,REVISION_QTY_CONTROL_CODE=BIGINT,ITEM_CATALOG_GROUP_ID=BIGINT,CATALOG_STATUS_FLAG=STRING,RETURNABLE_FLAG=STRING,DEFAULT_SHIPPING_ORG=BIGINT,COLLATERAL_FLAG=STRING,TAXABLE_FLAG=STRING,QTY_RCV_EXCEPTION_CODE=STRING,ALLOW_ITEM_DESC_UPDATE_FLAG=STRING,INSPECTION_REQUIRED_FLAG=STRING,RECEIPT_REQUIRED_FLAG=STRING,MARKET_PRICE=BIGINT,HAZARD_CLASS_ID=BIGINT,RFQ_REQUIRED_FLAG=STRING,QTY_RCV_TOLERANCE=BIGINT,LIST_PRICE_PER_UNIT=BIGINT,UN_NUMBER_ID=BIGINT,PRICE_TOLERANCE_PERCENT=BIGINT,ASSET_CATEGORY_ID=BIGINT,ROUNDING_FACTOR=BIGINT,UNIT_OF_ISSUE=STRING,ENFORCE_SHIP_TO_LOCATION_CODE=STRING,ALLOW_SUBSTITUTE_RECEIPTS_FLAG=STRING,ALLOW_UNORDERED_RECEIPTS_FLAG=STRING,ALLOW_EXPRESS_DELIVERY_FLAG=STRING,DAYS_EARLY_RECEIPT_ALLOWED=BIGINT,DAYS_LATE_RECEIPT_ALLOWED=BIGINT,RECEIPT_DAYS_EXCEPTION_CODE=STRING,RECEIVING_ROUTING_ID=BIGINT,INVOICE_CLOSE_TOLERANCE=BIGINT,RECEIVE_CLOSE_TOLERANCE=BIGINT,AUTO_LOT_ALPHA_PREFIX=STRING,START_AUTO_LOT_NUMBER=STRING,LOT_CONTROL_CODE=BIGINT,SHELF_LIFE_CODE=BIGINT,SHELF_LIFE_DAYS=BIGINT,SERIAL_NUMBER_CONTROL_CODE=BIGINT,START_AUTO_SERIAL_NUMBER=STRING,AUTO_SERIAL_ALPHA_PREFIX=STRING,SOURCE_TYPE=BIGINT,SOURCE_ORGANIZATION_ID=BIGINT,SOURCE_SUBINVENTORY=STRING,EXPENSE_ACCOUNT=BIGINT,ENCUMBRANCE_ACCOUNT=BIGINT,RESTRICT_SUBINVENTORIES_CODE=BIGINT,UNIT_WEIGHT=BIGINT,WEIGHT_UOM_CODE=STRING,VOLUME_UOM_CODE=STRING,UNIT_VOLUME=BIGINT,RESTRICT_LOCATORS_CODE=BIGINT,LOCATION_CONTROL_CODE=BIGINT,SHRINKAGE_RATE=BIGINT,ACCEPTABLE_EARLY_DAYS=BIGINT,PLANNING_TIME_FENCE_CODE=BIGINT,DEMAND_TIME_FENCE_CODE=BIGINT,LEAD_TIME_LOT_SIZE=BIGINT,STD_LOT_SIZE=BIGINT,CUM_MANUFACTURING_LEAD_TIME=BIGINT,OVERRUN_PERCENTAGE=BIGINT,MRP_CALCULATE_ATP_FLAG=STRING,ACCEPTABLE_RATE_INCREASE=BIGINT,ACCEPTABLE_RATE_DECREASE=BIGINT,CUMULATIVE_TOTAL_LEAD_TIME=BIGINT,PLANNING_TIME_FENCE_DAYS=BIGINT,DEMAND_TIME_FENCE_DAYS=BIGINT,END_ASSEMBLY_PEGGING_FLAG=STRING,REPETITIVE_PLANNING_FLAG=STRING,PLANNING_EXCEPTION_SET=STRING,BOM_ITEM_TYPE=BIGINT,PICK_COMPONENTS_FLAG=STRING,REPLENISH_TO_ORDER_FLAG=STRING,BASE_ITEM_ID=BIGINT,ATP_COMPONENTS_FLAG=STRING,ATP_FLAG=STRING,FIXED_LEAD_TIME=BIGINT,VARIABLE_LEAD_TIME=BIGINT,WIP_SUPPLY_LOCATOR_ID=BIGINT,WIP_SUPPLY_TYPE=BIGINT,WIP_SUPPLY_SUBINVENTORY=STRING,PRIMARY_UOM_CODE=STRING,PRIMARY_UNIT_OF_MEASURE=STRING,ALLOWED_UNITS_LOOKUP_CODE=BIGINT,COST_OF_SALES_ACCOUNT=BIGINT,SALES_ACCOUNT=BIGINT,DEFAULT_INCLUDE_IN_ROLLUP_FLAG=STRING,INVENTORY_ITEM_STATUS_CODE=STRING,INVENTORY_PLANNING_CODE=BIGINT,PLANNER_CODE=STRING,PLANNING_MAKE_BUY_CODE=BIGINT,FIXED_LOT_MULTIPLIER=BIGINT,ROUNDING_CONTROL_TYPE=BIGINT,CARRYING_COST=BIGINT,POSTPROCESSING_LEAD_TIME=BIGINT,PREPROCESSING_LEAD_TIME=BIGINT,FULL_LEAD_TIME=BIGINT,ORDER_COST=BIGINT,MRP_SAFETY_STOCK_PERCENT=BIGINT,MRP_SAFETY_STOCK_CODE=BIGINT,MIN_MINMAX_QUANTITY=BIGINT,MAX_MINMAX_QUANTITY=BIGINT,MINIMUM_ORDER_QUANTITY=BIGINT,FIXED_ORDER_QUANTITY=BIGINT,FIXED_DAYS_SUPPLY=BIGINT,MAXIMUM_ORDER_QUANTITY=BIGINT,ATP_RULE_ID=BIGINT,PICKING_RULE_ID=BIGINT,RESERVABLE_TYPE=BIGINT,POSITIVE_MEASUREMENT_ERROR=BIGINT,NEGATIVE_MEASUREMENT_ERROR=BIGINT,ENGINEERING_ECN_CODE=STRING,ENGINEERING_ITEM_ID=BIGINT,ENGINEERING_DATE=TIMESTAMP,SERVICE_STARTING_DELAY=BIGINT,VENDOR_WARRANTY_FLAG=STRING,SERVICEABLE_COMPONENT_FLAG=STRING,SERVICEABLE_PRODUCT_FLAG=STRING,BASE_WARRANTY_SERVICE_ID=BIGINT,PAYMENT_TERMS_ID=BIGINT,PREVENTIVE_MAINTENANCE_FLAG=STRING,PRIMARY_SPECIALIST_ID=BIGINT,SECONDARY_SPECIALIST_ID=BIGINT,SERVICEABLE_ITEM_CLASS_ID=BIGINT,TIME_BILLABLE_FLAG=STRING,MATERIAL_BILLABLE_FLAG=STRING,EXPENSE_BILLABLE_FLAG=STRING,PRORATE_SERVICE_FLAG=STRING,COVERAGE_SCHEDULE_ID=BIGINT,SERVICE_DURATION_PERIOD_CODE=STRING,SERVICE_DURATION=BIGINT,WARRANTY_VENDOR_ID=BIGINT,MAX_WARRANTY_AMOUNT=BIGINT,RESPONSE_TIME_PERIOD_CODE=STRING,RESPONSE_TIME_VALUE=BIGINT,NEW_REVISION_CODE=STRING,INVOICEABLE_ITEM_FLAG=STRING,TAX_CODE=STRING,INVOICE_ENABLED_FLAG=STRING,MUST_USE_APPROVED_VENDOR_FLAG=STRING,REQUEST_ID=BIGINT,PROGRAM_APPLICATION_ID=BIGINT,PROGRAM_ID=BIGINT,PROGRAM_UPDATE_DATE=TIMESTAMP,OUTSIDE_OPERATION_FLAG=STRING,OUTSIDE_OPERATION_UOM_TYPE=STRING,SAFETY_STOCK_BUCKET_DAYS=BIGINT,AUTO_REDUCE_MPS=BIGINT,COSTING_ENABLED_FLAG=STRING,AUTO_CREATED_CONFIG_FLAG=STRING,CYCLE_COUNT_ENABLED_FLAG=STRING,ITEM_TYPE=STRING,MODEL_CONFIG_CLAUSE_NAME=STRING,SHIP_MODEL_COMPLETE_FLAG=STRING,MRP_PLANNING_CODE=BIGINT,RETURN_INSPECTION_REQUIREMENT=BIGINT,ATO_FORECAST_CONTROL=BIGINT,RELEASE_TIME_FENCE_CODE=BIGINT,RELEASE_TIME_FENCE_DAYS=BIGINT,CONTAINER_ITEM_FLAG=STRING,VEHICLE_ITEM_FLAG=STRING,MAXIMUM_LOAD_WEIGHT=BIGINT,MINIMUM_FILL_PERCENT=BIGINT,CONTAINER_TYPE_CODE=STRING,INTERNAL_VOLUME=BIGINT,WH_UPDATE_DATE=TIMESTAMP,PRODUCT_FAMILY_ITEM_ID=BIGINT,GLOBAL_ATTRIBUTE_CATEGORY=STRING,GLOBAL_ATTRIBUTE1=STRING,GLOBAL_ATTRIBUTE2=STRING,GLOBAL_ATTRIBUTE3=STRING,GLOBAL_ATTRIBUTE4=STRING,GLOBAL_ATTRIBUTE5=STRING,GLOBAL_ATTRIBUTE6=STRING,GLOBAL_ATTRIBUTE7=STRING,GLOBAL_ATTRIBUTE8=STRING,GLOBAL_ATTRIBUTE9=STRING,GLOBAL_ATTRIBUTE10=STRING,PURCHASING_TAX_CODE=STRING,OVERCOMPLETION_TOLERANCE_TYPE=BIGINT,OVERCOMPLETION_TOLERANCE_VALUE=BIGINT,EFFECTIVITY_CONTROL=BIGINT,CHECK_SHORTAGES_FLAG=STRING,OVER_SHIPMENT_TOLERANCE=BIGINT,UNDER_SHIPMENT_TOLERANCE=BIGINT,OVER_RETURN_TOLERANCE=BIGINT,UNDER_RETURN_TOLERANCE=BIGINT,EQUIPMENT_TYPE=BIGINT,RECOVERED_PART_DISP_CODE=STRING,DEFECT_TRACKING_ON_FLAG=STRING,USAGE_ITEM_FLAG=STRING,EVENT_FLAG=STRING,ELECTRONIC_FLAG=STRING,DOWNLOADABLE_FLAG=STRING,VOL_DISCOUNT_EXEMPT_FLAG=STRING,COUPON_EXEMPT_FLAG=STRING,COMMS_NL_TRACKABLE_FLAG=STRING,ASSET_CREATION_CODE=STRING,COMMS_ACTIVATION_REQD_FLAG=STRING,ORDERABLE_ON_WEB_FLAG=STRING,BACK_ORDERABLE_FLAG=STRING,WEB_STATUS=STRING,INDIVISIBLE_FLAG=STRING,DIMENSION_UOM_CODE=STRING,UNIT_LENGTH=BIGINT,UNIT_WIDTH=BIGINT,UNIT_HEIGHT=BIGINT,BULK_PICKED_FLAG=STRING,LOT_STATUS_ENABLED=STRING,DEFAULT_LOT_STATUS_ID=BIGINT,SERIAL_STATUS_ENABLED=STRING,DEFAULT_SERIAL_STATUS_ID=BIGINT,LOT_SPLIT_ENABLED=STRING,LOT_MERGE_ENABLED=STRING,INVENTORY_CARRY_PENALTY=BIGINT,OPERATION_SLACK_PENALTY=BIGINT,FINANCING_ALLOWED_FLAG=STRING,EAM_ITEM_TYPE=BIGINT,EAM_ACTIVITY_TYPE_CODE=STRING,EAM_ACTIVITY_CAUSE_CODE=STRING,EAM_ACT_NOTIFICATION_FLAG=STRING,EAM_ACT_SHUTDOWN_STATUS=STRING,DUAL_UOM_CONTROL=BIGINT,SECONDARY_UOM_CODE=STRING,DUAL_UOM_DEVIATION_HIGH=BIGINT,DUAL_UOM_DEVIATION_LOW=BIGINT,CONTRACT_ITEM_TYPE_CODE=STRING,SUBSCRIPTION_DEPEND_FLAG=STRING,SERV_REQ_ENABLED_CODE=STRING,SERV_BILLING_ENABLED_FLAG=STRING,SERV_IMPORTANCE_LEVEL=BIGINT,PLANNED_INV_POINT_FLAG=STRING,LOT_TRANSLATE_ENABLED=STRING,DEFAULT_SO_SOURCE_TYPE=STRING,CREATE_SUPPLY_FLAG=STRING,SUBSTITUTION_WINDOW_CODE=BIGINT,SUBSTITUTION_WINDOW_DAYS=BIGINT,IB_ITEM_INSTANCE_CLASS=STRING,CONFIG_MODEL_TYPE=STRING,LOT_SUBSTITUTION_ENABLED=STRING,MINIMUM_LICENSE_QUANTITY=BIGINT,EAM_ACTIVITY_SOURCE_CODE=STRING,LIFECYCLE_ID=BIGINT,CURRENT_PHASE_ID=BIGINT,OBJECT_VERSION_NUMBER=BIGINT,CDB_DATA_SOURCE=STRING,CDB_ENQUEUE_TIME=TIMESTAMP,CDB_DEQUEUE_TIME=TIMESTAMP,CDB_ENQUEUE_SEQ=BIGINT --boundary-query 'select (select min(INVENTORY_ITEM_ID) from MTL_SYSTEM_ITEMS_B) as minid ,(select max(INVENTORY_ITEM_ID) from MTL_SYSTEM_ITEMS_B) as maxid from dual' " >> /apps/pentaho_nfs/installbase/input/poc/logs/IB_logs.log 2>&1"
public void run() {
ProcessBuilder processbuilder = new ProcessBuilder(command);
LOGGER.info(command);
try {
Process process = processbuilder.inheritIO().start();
System.out.println("inside process builder ");
process.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String readline;
while ((readline = reader.readLine()) != null) {
LOGGER.info(readline);
}
} catch (Exception e) {
LOGGER.error(e.getMessage());
}
}

Passing query from php to java

i em trying to fetch some query from an url and then pass them to a java program for further execution. The problem i am facing is that my php code is calling my java program but is not passing the values.
till now i have worked on these codes,
PHP PROGRAM:
<?php
$phonecode= $_GET['phonecode'];
$keyword= $_GET['keyword'];
$location= $_GET['location'];
exec("C:\Users\Abc\Documents\NetBeansProjects\JavaApplication11\src\javaapplication11\main.java -jar jar/name.jar hello" . $phonecode . ' ' . $keyword . ' ' . $location, $output);
print_r($output);
?>
JAVA PROGRAM:
public class Main
{
public static void main(String args[])
{
try
{
String phonecode = args[];
System.out.println(args[]);
System.out.println(phonecode);// i have only tried to print phonecode for now
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Ok, a couple of issues with the Java code you've posted, here's a working version of what you posted:
class Main
{
public static void main(String[] args)//String[] args, not String args[]
{
if (args.length == 0)
{//check to see if we received arguments
System.out.println("No arguments");
return;
}
if ( args.length < 3)
{//and make sure that there are enough args to continue
System.out.println("To few arguments");
return;
}
try
{//this try-catch block can be left out
String phonecode = args[0];//first arg
String keyword = args[1];//second
String location = args[2];//third
//print out the values
System.out.print("Phonecode: ");
System.out.println(phonecode);
System.out.print("keyword: ");
System.out.println(keyword);
System.out.print("location: ");
System.out.println(location);
}
catch(Exception e)
{
System.out.println(e.getMessage());//get the exception MESSAGE
}
}
}
Now, save that as a .java file, and compile it, it should churn out a Main.class file. I compiled it from the command-line:
javac main.java
I don't have netbeans installed, but I suspect the .class file will be written to a different directory, something like:
C:\Users\Abc\Documents\NetBeansProjects\JavaApplication11\bin\javaapplication11\Main.class
// note the BIN
Then, to execute, you need to run the java command, and pass it the path to this Main.class file, leaving out the .class extension. Thus, we end up with:
java /path/to/Main 123 keywrd loc
Should result in the output:
Phonecode: 123
keyword: keywrd
location: loc
In your PHP code:
exec('java /path/to/Main '.escapeshellarg($phonecode). ' '.escapeshellarg($keyword).' '.escapeshellarg($location), $output, $status);
if ($status === 0)
{//always check exit code, 0 indicates success
var_dump($output);
}
else
exit('Error: java exec failed: '.$status);
There are a couple of other issues, too: like $phonecode = $_GET['phonecode']; doesn't check if that $_GET param exists. If it doesn't your code will emit notices. To fix:
$phonecode = isset($_GET['phonecode']) ? $_GET['phonecode'] : '';
Other niggles include: the backslash is a special char in strings, it is used in escape sequences: \n is a newline char. PHP can deal with the *NIX directory separator /, even on windows. Use that, or escape the backslashes (C:\\Users\\Abc\\ and so on).
A file that only contains PHP code doesn't require the closing ?> tag. In fact: it is recommended you leave it out.
your java code should look like
public static void main (String[] args) {
for (String s: args) {
System.out.println(s);
}
}
Note String[] args, not String args[]
Also on PHP side in exec you need space between string hello, and variable $phonecode if you want those to be looked as a 2 separate arguments.

Execute jar file many times and analyse output

I'd like to test which of two implementation in java of a problem is the fastest.
I've 2 jar files with the two implementation I can execute from the terminal. I want to execute both about 100 times and analyse which one is the fastest to do that or that task.
In the output one of the line is "executing time : xx", I need to catch this xx to put in an array or something like that to analyse it later
While I'm executing the jar, I've also to give some input commands (like a name to search or a number).
I don't with which language is it the easiest to do it.
I know the basis in Bash and Python
thank you
Excuse me, but Why you dont make a jar that call n-times any jar?
For Example:
public static void main(String[] args) {
for(int i=0;i<1000;i++) {
params1 = randomNumber();
params2 = randomName();
...
paramsN = randomTime();
MYJAR1 test1 = new MYJAR1(params1,params2,...,paramsN);
timerStart();
test1.start();
timerEnd();
printTimer();
}
}
and make the same for the second jar.
I hope that my idea can help you.
Bye
If you use (say) Perl, you can spawn the process off, capture the output via a redirection and filter the times. e.g.
if (open(PROCESS, "myproc |")) {
while(<PROCESS>) {
if (/executing time : (\d+)/) {
# $1 has the time now
}
}
}
(not compiled or tested!)
Perhaps the simplest way of analysing the data is to redirect the above output to a file, and then load it into Excel. You can then use Excel to calculate averages/max/mins and std. devs (if you wish) trivially.
Ok I've found with 3 different scripts ^^
in the java code, for each function :
long time1 = System.currentTimeMillis();
// some code for function 1
long time2 = System.currentTimeMillis();
try {
OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(new File("log.txt"),true));
osw.write("function1,"+(time2 - time1)+"\n");
osw.close();
} catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
a bash code to run the 500 times the two algorithms
#!/bin/bash
i=0
while [ $i -lt 500 ]
do
./algo1.ex
./algo2.ex
i=$(( $i+1 ))
done
an (or two actually, one for each algorithm) expect code to do the command during the execution
#!/usr/bin/expect -f
spawn java -jar algo1.jar
expect "enter your choice" {send "1\n"}
expect "enter a name :" {send "Peju, M.\n"}
expect "enter your choice" {send "2\n"}
expect "enter a name :" {send "Creasy, R. J.\n"}
expect "enter your choice" {send "0\n"}
exit
As I didn't know how to do it in bash, to count I used a python code
#!/usr/bin/python
# -*- coding: utf8 -*-
import sys
if __name__ == "__main__":
if sys.argv[1:]:
arg = sys.argv[1]
filin = open(arg, 'r')
line = filin.readline()
res= 0, 0, 0
int n = 1
while line !='':
t = line.partition(',')
if t[0] == "function1":
res = (res[0] + int(t[2]), res[1], res[2])
if t[0] == "function2":
res = (res[0], res[1] + int(t[2]), res[2])
if t[0] == "function3":
res = (res[0], res[1], res[2] + int(t[2]))
ligne = filin.readline()
n = n+1
print res
print (res[0]/(n/3.0), res[1]/(n/3.0), res[2]/(n/3.0))
filin.close()
and it works
but thanks for your propositions

Categories