GetVariableData in Java Exec
I am trying get a variable data using gatVariableData but it prints the data from the variable correctly but when ever I tried to compare it I couldn't. Here is the scenario.
I have the variable ContactsMaster/sex
when I print it using getVariableData it prints properly as 'MALE'
However, I need to convert it as number '1' if MALE and '2' if FEMALE else 0.
When I tried to compare using java it always returns '0'
What I noticed was it is comparing the whole string like
<sex>MALE</sex> instead of taking the value 'MALE'
Can any body advise me how to get the value?
The below worked for me in 10.1.3.1 :-
org.w3c.dom.Node firstChild = null;
String requestType = "";
firstChild = ((oracle.xml.parser.v2.XMLElement) getVariableData("inputVariable", "payload", "/ns1:SwipeCardRequest/ns1:RequestType")).getFirstChild();
if (firstChild != null)
requestType = firstChild.getNodeValue();
addAuditTrailEntry("***** requestType = " + requestType);
Thanks,
Gopal D. Kalsekar
M.H. Alshaya Co. WLL.
Off. Tel. :- (965) 224 3598
Email :- [email protected]
Similar Messages
-
Unable to call getVariableData from java exec
Hi,
I am trying to call getVariableData("inFile") from a java exec. However, I get the following error:
<2005-01-18 11:40:37,506> <DEBUG> <default.collaxa.cube.engine> <bpel._1_0.SyncHello__BPEL4WS_BIN$$BPELC_BxExe22::perform> error thrown
com.collaxa.cube.engine.types.BPELFault: faultName: {{http://schemas.oracle.com/bpel/extension}javaException}
messageType: {{http://schemas.oracle.com/bpel/extension}javaException}
code: {null}
summary: {null}
detail: {null}
at com.collaxa.cube.engine.ext.wmp.BPELXExecWMP.__executeStatements(BPELXExecWMP.java:66)
at com.collaxa.cube.engine.ext.wmp.BPELActivityWMP.perform(BPELActivityWMP.java:154)
at com.collaxa.cube.engine.CubeEngine.performActivity(CubeEngine.java:3215)
at com.collaxa.cube.engine.CubeEngine.handleWorkItem(CubeEngine.java:1636)
In the .bpel file, I have declared the variable as follows:
<variable name="inFile" type="xsd:string"/>
I have assigned values to this variable in two different ways (using the assign tag and also through a java exec call):
<assign>
<copy>
<from expression="'inFile.txt'"/>
<to variable="inFile"/>
</copy>
</assign>
OR alternatively:
setVariableData("inFile", new String("inFile.txt"));
After this I attempt to call (this is the part that throws the error):
CubeDOMElement el = (CubeDOMElement) getVariableData("inFile");
The strange thing is that I am able to get the variable from inside an assign activity as follows:
<assign name="setOutputVars">
<copy>
<from expression="bpws:getVariableData('inFile')"/>
<to variable="output" part="payload"
query="/outputMessage"/>
</copy>
</assign>
This assign works perfectly and outputs the correct value.
Any suggestions would be greatly appreciated.
Thanks.I have a similar problem, but I try to retreive a complex object.
The assign activity successfully copy data to the variable 'DMSPollingInput'.
Here is my code:
Element element = (Element) getVariableData("DMSPollingInput");
System.out.println("Receive Poll and execute enqueue ");
if(element==null) System.out.println("element is null ");
else System.out.println("element is not null ");
IDmsPollingsCollection requests =
IDmsPollingsCollectionFactory.createFacade(element);
if(requests==null) System.out.println("requests is null ");
else System.out.println("requests is not null ");
List dmsPollings = requests.getIDmsPollings();
int count = dmsPollings.size();
System.out.println("Poll size: " + count);
The count always equals to 0.
Please help -
If i start a command with java exec and i want to terminate the command from running how to i do this?
what i am doing now is i wait 5 seconds and if there is no output from the command i ask for exitValue() which throws an exception which i catch.
This causes my main function to exit, but my two command output readers threads continue to read because the process is still alive.
How do i kill the process? i tried to use destroy but its depreciated. Thanks in advance for the help.Tommaso wrote:
I got my self so confused with depreciated methods like stop()Again, there is a significant difference between depreciated and deprecated.
http://www.thefreedictionary.com/Depreciated
http://www.thefreedictionary.com/Deprecated -
XML Parser Error in bpel java exec code
hi,
When BPEL PM is loading processes from the deploy directory, the following exception is thrown. Any thoughts on why this XML error is being thrown ? Also, this problem is not consistently reproducible.
Thanks,
Ravikiran
bpel<Line 232, Column 72>: XML-24523: (Error) Invalid value 'NotifyFoo' for attribute: 'name'.
[Potential fix]: Fix the invalid XML.
at com.collaxa.cube.lang.compiler.CubeProcessor.validateServerSide(CubeProcessor.java:1156)
at com.collaxa.cube.lang.compiler.CubeProcessor.transformServerSide(CubeProcessor.java:627)
at com.collaxa.cube.lang.compiler.CubeParserHelper.compileServerSide(CubeParserHelper.java:132)
at com.collaxa.cube.engine.deployment.CubeProcessFactory.generateProcessClass(CubeProcessFactory.java:239)
39,0-1 10%One more piece of information that may be relevant. There are 4 BPEL processes that are deployed (copied into deploy directory) that all have "NotifyFoo" java exec element. Is it that somehow some parser is seeing this "name" attribute "NotifyFoo" refered to in two processes as being used twice in the same process? Perhaps this is because the element is a Java code ?
Thanks,
Ravikiran -
Java exec spawns command window
Hello,
I am using JRE 1.4.2 (Eclipse runtime environment). Whenever I execute the following command:
System.getRuntime().exec("<some command>");
I am getting a Command Window that pops up while the process executes and closes afterwords.
Is there any way to prevent this command window from appearing. I have chained all Error and Output streams within the java program but no luck. I guess the only other solution is to not make the exec calls by making native calls from the java program, but that would be a huge undertaking.
Thanks in advance.Yes, I think you are correct.
When I do the same with say calc.exe or notepad.exe, I do not get this dos command prompt.
The command that I am trying to execute here is PCLI.exe (for PVCS). Do you have an idea of how I can deal with this program so that I do not get that annoying comand prompt? -
Java exec() child termination problem
Hello,
I am trying to use exec() to launch a java application from a Java Swing GUI. The problem is that If any of the applications call System.exit() or Runtime.exit(), all applications will terminate. How do I prevent the GUI from closing when the child closes? I have attached the code I am using for reference.
Thanks in advance
public void COmpileAndRun()
String command = "javac Driver.java";
try
Runtime rt = Runtime.getRuntime(); //Process process = new ProcessBuilder(command).start();
Process proc = rt.exec( command ); //Process process = new ProcessBuilder(command).start();
InputStream stderr = proc.getErrorStream();
InputStreamReader isr = new InputStreamReader(stderr);
BufferedReader br = new BufferedReader(isr);
String line = null;
System.out.println("<ERROR>");
while ( (line = br.readLine()) != null)
System.out.println(line);
System.out.println("</ERROR>");
int exitVal = proc.waitFor();
System.out.println("Process exitValue: " + exitVal);
if( exitVal == 0 )
command = "java Driver";
proc = rt.exec( command );
stderr = proc.getErrorStream();
isr = new InputStreamReader(stderr);
br = new BufferedReader(isr);
line = null;
System.out.println("<ERROR>");
while ( (line = br.readLine()) != null)
System.out.println(line);
System.out.println("</ERROR>");
exitVal = proc.waitFor();
System.out.println("Process exitValue: " + exitVal);
} catch (Throwable t)
t.printStackTrace();
}String[] command =
"java",
"-cp",
"my_class_path", // No extra quoting needed here
"org.jetel.main.runGraph",
"param1",
"param2",
"param3" // etc
Process process = Runtime.getRuntime().exec(command); -
Java exec() of UNIX shell script
I have a java application that uses:
p = Runtime.getRuntime().exec( cmdLine);
to execute a UNIX shell script, for example:
#!/bin/ksh
. /export/pc112477/freeware/work1/wsEnv
export PATH=/opt/sfw/bin:/usr/ccs/bin:/usr/bin:/usr/ucb:$PATH
cd /export/pc112477/freeware/work1/usr/src/pkgdefs/SFWnmap
/usr/ccs/bin/make -e ROOT=$ROOT install
RESULT=$?
if [ $RESULT = 0 ]
then
echo "Package source"
cd /export/pc112477/freeware/work1/usr/src/pkgdefs/SFWnmapS
/usr/ccs/bin/make -e ROOT=$ROOT install
RESULT=$?
fi
exit $RESULT
Some times the running of the script locks up depending on how much work the script has to, eg. if the make calls pkgmk for a small package it runs okay but if its a large package it locks up in pkgmk.
The script itself works okay if run directly
Does anyone have any ideas on why this locks up and how I could stop it doing it.
ThanksFor anyone who stumbles across this and needs an answer:
To empty the standard error and output, you need to use getErrorStream() and getInputStream() on the Process object created when you execed your command. Create new InputStreamReaders with the streams from the process, then wrap those with BufferedReaders and read each line with a while loop. This is the basic thing you need to do:
try{
Process proc = Runtime.getRuntime().exec(command);
InputStreamReader isr = new InputStreamReader(proc.getErrorStream());
BufferedReader errReader = new BufferedReader(isr);
String line;
while((line = errReader.readLine()) != null)
<do something with each line of error>
} //end try
catch(<errors>) {
<do something with errors>
} //end catch
What you really should do is put the stream handling in a separate class that extends Thread, create an instance for the error and output streams, and start each one. There is a class called StreamGobbler that does this sort of thing. Look at http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html to find out more about it and read a detailed explanation of different problems with exec(). -
GetVariableData() in Java Embedding Activity
In Oracle BPEL PM 10.1.3, getVariableData() method now returns 'oracle.xml.parser.v2.XMLElement' instead of the usual DOM element.
String input = ((XMLElement)getVariableData("inputVariable","payload","/ns1:input")).getNodeValue();
The above code snippet for me simply returns a 'null'. Note: 'ns1:input' is of type 'xsd:string'.
In case any one comes across this issue, try this alternative which works fine:
String input = ((XMLElement)getVariableData("inputVariable","payload","/ns1:input")).getText();Try out :
String input = ((XMLElement)getVariableData("inputVariable","payload","/ns1:input")).getFirstChild().getNodeValue();
HTH
Rahul -
I am using the exec comnd to get 2 networking commnds' result but I am able to get only one. Here is the piece of code - any suggestion.
Thanks.
public class VariousNetwrkCommands {
Process Findspace;
public void ExecutePingCommand() throws IOException
String [] Command = {"ping"};
Findspace = Runtime.getRuntime().exec(Command);
BufferedReader Resultset = new BufferedReader(
new InputStreamReader (
Findspace.getInputStream()));
String line;
while ((line = Resultset.readLine()) != null) {
System.out.println(line);
Findspace.destroy();
public void ExecuteNetstatCommand() throws IOException
String [] Command = {"dir"};
Findspace = Runtime.getRuntime().exec(Command);
BufferedReader Resultset2 = new BufferedReader(
new InputStreamReader (
Findspace.getInputStream()));
String line2;
while ((line2 = Resultset2.readLine()) != null) {
System.out.println(line2);
Findspace.destroy();
}ashum wrote:any suggestion.1) At least tell us which one works.
2) Read, digest and implement the recommendations in http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html . -
Use of bpelx built-in methods like getVariableData in custom java classes
Hi,
how can I use bpelx built-in methods like getVariableData ...
inside custom java classes embedded with BPEL project?
I have large java code to embed with BPEL process
and it will be very useful ....
It is possible to access these methods like static methods of some class?
import com.xxx.yyy.class;
class.getVaribleData("inputVariable","payload","/ns1:mailMessage/ns1:content/ns1:multiPart");
Regards
Karelyou can access them from <bpelx:exec> activity and you can pass these returned document to underlying java class.
Re: getVariableData in Java Exec -
Calling java classes using bpelx:exec (Java Embedding) Erorr
I try to add java embedding activity.
So, I add code in this activity:
<bpelx:exec name="Java_Embedding_1" language="Java" version="1.4"><![CDATA[Element ele=(Element)getVariableData("/StringForSubject");
]]>
</bpelx:exec>
where ("/StringForSubject") is local variable of scope activity, where situated java embedding activity.
Try to compile, but JDeveloper show error message:
Error: Java compilation failed. Failed to compile file(s) "test.bpel". Exception reported is: test.bpel:1156: Class bpel.p0.Element not found. Element ele=(Element)getVariableData("/StringForSubject"); ^ test.bpel:1156: Class bpel.p0.Element not found. Element ele=(Element)getVariableData("/StringForSubject"); ^ 2 errors Please verify that file test.bpel is valid java file or if all required libraries are included in your classpath.
How can i solve this problem.
Thank You!!!!add an import at the top of the process .. or specify the package ..
org.w3c.dom.Element
hth clemens -
Getting Error: SCAC-50012 while using Java Embeding Activity
Hi,
I am using Jdeveloper 11.1.1.4.0 . I am using a Java Embedding Activity in my BPEL and when i compile the project, i got one error------Error: SCAC-50012
The code i am using in Java Embedding activity is
java.lang.String TraceLogMessage = null;
java.lang.Boolean tracelogenabled;
java.lang.String title = (java.lang.String)getVariableData("Title");
java.lang.String instanceID = (java.lang.String)getVariableData("InstanceID");
java.lang.String serviceName = (java.lang.String)getVariableData("ServiceName");
tracelogenabled = oracle.apps.aia.core.eh.logging.AIALogger.isTraceLoggingEnabled("INFO","http://xmlns.oracle.com/ExecuteSalesOrderFulfillmentDeviceUpdateEBF");
setVariableData("TraceLogEnabled", tracelogenabled);
if (tracelogenabled.booleanValue())
TraceLogMessage = "Starting " + serviceName + " Instance: " + instanceID + title; ;
oracle.apps.aia.core.eh.logging.AIALogger.logTraceMessage("INFO", null ,TraceLogMessage);
i have imported the following in bpel but there is no luck........
<bpelx:exec import="java.util.logging.Logger"/>
<bpelx:exec import="java.util.logging.Level"/>
<bpelx:exec import="oracle.fabric.logging.LogFormatter"/>
<bpelx:exec import="org.w3c.dom.*"/>
<bpelx:exec import="oracle.xml.parser.v2.XMLElement"/>
<bpelx:exec import="java.util.*"/>
<bpelx:exec import="java.lang.*"/>
<bpelx:exec import="java.math.*"/>
<bpelx:exec import="java.io.*"/>
<bpelx:exec import="oracle.soa.common.util.Base64Decoder"/>
Please help me with this......
Thanks&Regards,
sumanHi Lara,
Thanks for the responce.......
I checked the scac log file it contains the following code.
---------------------------------------------- scac logfile ----------------------------------------------------
Mar 15, 2012 5:32:18 PM com.collaxa.cube.CubeLogger info
INFO: validating "BPELProcess1.bpel" ...
oracle.jrf.UnknownPlatformException: JRF is unable to determine the current application server platform.
at oracle.jrf.ServerPlatformSupportFactory.getInstance(ServerPlatformSupportFactory.java:79)
at oracle.integration.platform.blocks.WLSPlatformConfigurationProvider.<clinit>(WLSPlatformConfigurationProvider.java:44)
at oracle.integration.platform.blocks.FabricConfigManager.<clinit>(FabricConfigManager.java:154)
at oracle.integration.platform.blocks.xpath.FabricXPathFunctionResolver.loadXpathFunctions(FabricXPathFunctionResolver.java:282)
at oracle.integration.platform.blocks.xpath.FabricXPathFunctionResolver.loadXPathConfigFile(FabricXPathFunctionResolver.java:156)
at oracle.integration.platform.blocks.xpath.FabricXPathFunctionResolver.init(FabricXPathFunctionResolver.java:49)
at com.collaxa.cube.xml.xpath.BPELXPathFunctionNameResolver.loadFabricXpathFunctions(BPELXPathFunctionNameResolver.java:57)
at com.collaxa.cube.xml.xpath.BPELXPathFunctionNameResolver.<init>(BPELXPathFunctionNameResolver.java:48)
at com.collaxa.cube.xml.xpath.BPELXPathFunctionNameResolver.<clinit>(BPELXPathFunctionNameResolver.java:44)
at com.collaxa.cube.lang.compiler.bpel.XPathExprValidatorVisitor.<init>(XPathExprValidatorVisitor.java:122)
at com.collaxa.cube.lang.compiler.bpel.AssignValidator.<init>(AssignValidator.java:89)
at com.collaxa.cube.lang.compiler.bpel.BpelParser.<init>(BpelParser.java:452)
at com.collaxa.cube.lang.compiler.bpel.BPELValidator.validate(BPELValidator.java:60)
at com.collaxa.cube.lang.compiler.BPEL1Processor.validate(BPEL1Processor.java:329)
at com.collaxa.cube.lang.compiler.BPEL1Processor.process(BPEL1Processor.java:153)
at com.collaxa.cube.lang.compiler.CubeParserHelper.compile(CubeParserHelper.java:47)
at oracle.fabric.bpel.bpelc.BPELComponentValidator.validate(BPELComponentValidator.java:40)
at oracle.soa.scac.ValidateComposite.validateComponentTypeServicesReferences(ValidateComposite.java:1117)
at oracle.soa.scac.ValidateComposite.doValidation(ValidateComposite.java:500)
at oracle.soa.scac.ValidateComposite.run(ValidateComposite.java:150)
at oracle.soa.scac.ValidateComposite.main(ValidateComposite.java:135)
Mar 15, 2012 5:32:23 PM CubeProcessGenerator compile
WARNING: classpath is: D:\Oracle\Middleware\jdeveloper\jdev\extensions\oracle.sca.modeler.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.fabric_11.1.1\fabric-runtime.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.mgmt_11.1.1\soa-infra-mgmt.jar;D:\Oracle\Middleware\oracle_common\modules\oracle.fabriccommon_11.1.1\fabric-common.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.bpel_11.1.1\orabpel.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.mediator_11.1.1\mediator_client.jar;D:\Oracle\Middleware\oracle_common\modules\oracle.mds_11.1.1\mdsrt.jar;;C:\JDeveloper\mywork\sampleApplication\JavaEmbed\SCA-INF\classes;C:\JDeveloper\mywork\sampleApplication\JavaEmbed\SCA-INF\classes;C:\JDeveloper\mywork\sampleApplication\JavaEmbed\SCA-INF\gen-classes;D:\Oracle\Middleware\oracle_common\modules\commonj.sdo_2.1.0.jar;D:\Oracle\Middleware\oracle_common\modules\oracle.fabriccommon_11.1.1\fabric-common.jar;D:\Oracle\Middleware\oracle_common\modules\oracle.xdk_11.1.0\xmlparserv2.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.bpel_11.1.1\bpel1-1-xbeans.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.bpel_11.1.1\orabpel-common.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.bpel_11.1.1\orabpel.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.bpel_11.1.1\bpel_coherence_config.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.bpel_11.1.1\orabpel-exts.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.bpel_11.1.1\thirdparty.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.bpel_11.1.1\bpm-analytics.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.bpel_11.1.1\orabpel-thirdparty.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.bpel_11.1.1\wsif-binding.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.bpel_11.1.1\orabpel-validator.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.bpel_11.1.1\monitor-rt-xbean.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.bpel_11.1.1\oracle.soa.bpmn.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\user-patch.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.thirdparty.jar;D:\Oracle\Middleware\jdeveloper\uddi\lib\oracle.soa.uddi.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.fabric_11.1.1\bpm-infra.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.fabric_11.1.1\testfwk-xbeans.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.fabric_11.1.1\fabric-ext.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.fabric_11.1.1\soa-infra-scheduler.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.fabric_11.1.1\xmlunit-1.1.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.fabric_11.1.1\fabric-runtime.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.fabric_11.1.1\soa-infra-tools.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.fabric_11.1.1\soa-xpath-exts.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.fabric_11.1.1\oracle-soa-client-api.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.wls.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.fabric_11.1.1\fabric-client.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.fabric_11.1.1\fabric-runtime-ext-was.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.fabric_11.1.1\fabric-runtime-ext-wls.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.fabric_11.1.1\oracle.soa.fabric.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.ext_11.1.1\classes;D:\Oracle\Middleware\oracle_common\soa\modules\oracle.soa.mgmt_11.1.1\soa-infra-mgmt.jar
Please help me how can i solve this issue.
Thanks&Regards,
Suman -
How to: Transform Activity: Read global/local variable, execute java code
Could anyone please show me how to do that???
could you please elaborate your usecase? yes you can read global variable using getVariableData( ) xpath function and pass them as an argument to the processXSLT ( ) xpath function.
You can read the global or local variables inside java exec using, please refer samples/references/javaexec sample. -
[SOLVED] Problem with Vuze and Java RE x86_64
Hello all !
First of all, sorry if this issue was posted before, but find no related issue similar to mine.
Using pacman, I successfully installed JRE (version 6u16-1-x86_64) and Vuze (version 4.2.0.8-1, former Azureus), but Vuze doesn't want to start.
Running the Vuze's executable in the gnome-terminal, I notice messages from vuze informing it can't find Java executable ("Java exec not found in PATH, starting auto-search..." AND "OOPS, unable to locate java exec in /usr/java/latest /usr/java /usr/lib/jvm/latest /usr/lib/jvm hierarchy") and therefore cannot start the Vuze UI. I also tried but failed in verify the version of Java with the command "java -version" due to command not found.
What is the best approach to fix this problem with Java 64 bits?
Thanks in advance
Last edited by josephg (2009-09-28 18:55:56)peart wrote:Just log out and back in, most likely. There are scripts in /etc/profile.d/ that need to be run to set up your java environment. They get run automatically when you log in.
Yep, perfect answer - issue solved. Thanks a lot! -
Runtime exec freezes: exec target is a executable .jar that requires stdin
I am having a problem with the Runtime.getRuntime().exec methodology in the following scenerio:
-- Exec.class is a program that uses a StreamGobbler to display stdout to the screen
-- ReadInput.class is a program that requires the user enter information via the console, using stdin
When I try to do this, the ReadInput.class locks up and freezes, presumably because its trying to use stdin which already has been gobbled up by the Exec.class ???
Here is my code, for example, that I run with the following command (on Windows XP) :
start.bat
@echo off
echo.
javac *.java
echo First, test the Exec.class to see if it works
echo.
java Exec "dir *.java"
echo.
echo Then, try to run a program that wants the stdin (click a key to continue)
echo.
pause>nul
java Exec "java -cp . ReadInput"
echo.
echo (click a key to end)
pause>nul
Exec.java
import java.util.*;
import java.io.*;
class StreamGobbler extends Thread
InputStream is;
String type;
StreamGobbler(InputStream is, String type)
this.is = is;
this.type = type;
public void run()
try
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line=null;
while ( (line = br.readLine()) != null)
System.out.println(type + ">" + line);
} catch (IOException ioe)
ioe.printStackTrace();
public class Exec
public static void main(String args[])
if (args.length < 1)
System.out.println("USAGE: java Exec <cmd>");
System.exit(1);
try
String osName = System.getProperty("os.name" );
System.out.println(osName);
String[] cmd = new String[3];
if( osName.equals( "Windows XP" ) )
cmd[0] = "cmd.exe" ;
cmd[1] = "/C" ;
cmd[2] = args[0];
else if( osName.equals( "Linux" ) )
cmd[0] = "command.com" ;
cmd[1] = "/C" ;
cmd[2] = args[0];
Runtime rt = Runtime.getRuntime();
System.out.println("Execing " + cmd[0] + " " + cmd[1] + " " + cmd[2]);
Process proc = rt.exec(cmd);
// any error message?
StreamGobbler errorGobbler = new
StreamGobbler(proc.getErrorStream(), "ERR");
// any output?
StreamGobbler outputGobbler = new
StreamGobbler(proc.getInputStream(), "OUT");
// kick them off
errorGobbler.start();
outputGobbler.start();
// any error???
int exitVal = proc.waitFor();
System.out.println("ExitValue: " + exitVal);
} catch (Throwable t)
t.printStackTrace();
public class ReadInput {
public static void main (String[] args) {
// prompt the user to enter their name
System.out.print("Enter your name: ");
// open up standard input
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String userName = null;
// read the username from the command-line; need to use try/catch with the
// readLine() method
try {
userName = br.readLine();
} catch (IOException ioe) {
System.out.println("IO error trying to read your name!");
System.exit(1);
System.out.println("Thanks for the name, " + userName);
} // end of ReadInput classEdited by: sabre150 on 21-Jul-2011 11:26
Added [ code] tags to make the code readable.When you call proc.getInputStream(), you are opening an InputStream in your app to read from the process's stdout.
If that process "needs stdin", that is, if it normally runs by a user typing stuff at a terminal after it launches, then you have to call proc.getOutputStream() to get an OutputStream that your app can use to feed the process's stdin. So if you're trying to have your app read from the terminal (your app's stdin/System.in) and push that to the process you're launching, then after reading a line from System.in, your app would need to write that line to the OutputStream that you get from proc.getOutputStream().
Maybe you are looking for
-
I could not transfer photos from iphone to macbook through iphoto. It is giving an error " could not be imported, file is in unrecognized format"
-
CSS -Can TCP port number under the VIP be different to real server TCP Port
Client TCPrt : 80 -----------------------------> CSS VIP to the actual server on TCP port 5555 --------------> Server The requirement is that client will send a request to VIP on port 80 and VIP has to forward the request to server on a different por
-
List of cubes - olap2_aw_cube_measures
I am having set of cubes available in the AWM schemas. But when I query the table olapsys.olap2_aw_cube_measures the available cubes are not showing up even all the grants are there properly. thanks,
-
Adding/Deleting rows in a Table
I am trying to get a couple of buttons to work in a table to add/delete rows. I have followed the directions in the LiveCycle designer help and it isn't working. In a test setup the only difference I can see from the help file is my Table is called T
-
Anyone know the name of this desktop customization software?
Hi guys, Some time ago now I saw an application somewhere that allows you to customize your desktop (or wallpaper, depending on what you call it) in more advanced ways than OS X normally allows. It allowed you to put images of your own on it; not in