Using the Process.getOutputStream() method

Hi all,
i have written a java program that executes System commands and returns output...
this program works fine if you want to only execute the command and returns output...
but suppose that the program that you executed waits for you to input something before returning ouput?!!
i suppose i have to use the Process.getOutputStraem() method in my prog!
but i don't know how to do that :-(
can any one help me to refine the prog to handle this case !
thanks a lot
here is the code:
import java.util.*;
import java.io.*;
class StreamGobbler extends Thread
    InputStream is;
    String type;
    OutputStream os;
    StreamGobbler(InputStream is, String type)
        this(is, type, null);
    StreamGobbler(InputStream is, String type, OutputStream redirect)
        this.is = is;
        this.type = type;
        this.os = redirect;
    public void run()
        try
            PrintWriter pw = null;
            if (os != null)
                pw = new PrintWriter(os);
            InputStreamReader isr = new InputStreamReader(is);
            BufferedReader br = new BufferedReader(isr);
            String line=null;
            while ( (line = br.readLine()) != null)
                if (pw != null)
                    pw.println(line);
                System.out.println(type + ">" + line);   
            if (pw != null)
                pw.flush();
        } catch (IOException ioe)
            ioe.printStackTrace(); 
public class GoodWinRedirect
    public static void main(String args[])
        if (args.length < 1)
            System.out.println("USAGE java GoodWinRedirect <outputfile>");
            System.exit(1);
        try
            FileOutputStream fos = new FileOutputStream(args[0]);
            Runtime rt = Runtime.getRuntime();
            Process proc = rt.exec("java jecho 'Hello World'");
            // any error message?
            StreamGobbler errorGobbler = new
                StreamGobbler(proc.getErrorStream(), "ERROR");           
            // any output?
            StreamGobbler outputGobbler = new
                StreamGobbler(proc.getInputStream(), "OUTPUT", fos);
            // kick them off
            errorGobbler.start();
            outputGobbler.start();
            // any error???
            int exitVal = proc.waitFor();
            System.out.println("ExitValue: " + exitVal);
            fos.flush();
            fos.close();       
        } catch (Throwable t)
            t.printStackTrace();
}

it's true that i've copied it and pasted it...
but i do understand how it works (really)
the article mentioned at last that we could send input
to the Program by invoking getoutputStream
i guess that we should write a construtor for the
streamGobbler class but this time using a
OutputStreamReader and may be doing sth elseThe "Gobbler" is there to eat up whatever bytes become available on an InputStream (from the program's output). I don't think ou just want to try to use the same class to handle the program's input.
The Gobbler can be used for eating up whatever comes out of any program--it' general, and doesn't rely on any particular output from the program (input to the Gobler). This is not the case for whatever writes to the program's input. You'll need to write what the program expects in the proper order.

Similar Messages

  • I would like to download a production desciption into my website like I have before, but it says I can't use the copy/paster method anymore. Why?

    I have a website - www.pawsitivepamperings.com, and I have been adding products for the last 6 months. I have been using the copy/paste method from my drop shipper. Since the end of last week, it hasn't been working. It has totally stopped my progress! I need help in using this function again - as soon as possible. Can you help me?

    I right click, and Copy from an HTML description from my drop shipper. Then I go to my website and right click to Paste.
    One of two things happens. (1) if it does copy, the text prints over the image; OR (2) I get a message that Firefox does not apply a Cut/Copy/Paste.
    The wording at the bottom of the description box says: Path: table> tbody> tr> td> p> font.
    I was told by my webmaster to eliminate the following but I don't see it on my products page: <table align="center" border="0" cellpadding="1" cellspacing="1" width="100%>.
    When I have been on a 'live chat' with my support team, a couple of them have overridden the issue and I could precede, but I go to the next product to add, the whole process starts again and I cannot proceed.
    Does this make sense?

  • How to extend the execution time of an ABAP Program using the Process chain

    Hello Sapians,
    Our Environment has got 600seconds = 10 mintues as the execution time.
    My ABAP Program is taking more than this 600 seconds, to show the result, I found this when I tried to execute in debug mode, it shows the result.
    If I execute in background also it shows the results succesfully.
    Only issue is when I execute this report in foreground it has been taking ages and goes on Time OUT Error.
    It has been decided that we can extend the execution time only for this report, and it will reset the time back to 10mintues once the report has been executed successfully or failed in between for any other reasons.
    And we can achieve this by using the process chains.
    Can any body help me please in this regard
    Thanks,

    Hi,,,,,,,,,,
    Besides Process Chain There is another way out for this........
    Resetting time counter of dialog process so that time-out does not
    happen. Use this fm within your program at appropriate locations to
    reset time counter.
    "CALL FUNCTION 'TH_REDISPATCH'."
    Thanks
    Saurabh

  • I found my old ipod and i forgot the passcode. It doesnt have an home button so i dont know how to put it in recovery mode so i can restore it. Ive been using the assisted touch method. But what should i do to put it in recovery mode

    i found my old ipod and i forgot the passcode. It doesnt have an home button so i dont know how to put it in recovery mode so i can restore it. Ive been using the assisted touch method. But what should i do to put it in recovery mode so i can restore it.

    Use this program to place the iPod in recovery mode
    RecBoot: Easy Way to Put iPhone into Recovery Mode

  • [svn] 3520: Add ability to use the FP10 unloadAndStop() method in SWFLoader .

    Revision: 3520
    Author: [email protected]
    Date: 2008-10-08 10:26:39 -0700 (Wed, 08 Oct 2008)
    Log Message:
    Add ability to use the FP10 unloadAndStop() method in SWFLoader.
    An application needs to be compiled with the "-target-player=10" argument to allow SWFLoader's unloadAndStop() function to use the Flash Player's unloadAndStop() function. If the argument is not provided then the Flash Player unload() function will be called instead.
    QE: YES
    Doc: YES
    Checkintests: YES
    Reviewer: Ely, Deepa
    Bugs: SDK-16764
    SWFLoader.as
    Added new public method unloadAndStop().
    Ticket Links:
    http://bugs.adobe.com/jira/browse/SDK-16764
    Modified Paths:
    flex/sdk/branches/3.0.x/frameworks/projects/framework/src/mx/controls/SWFLoader.as

    Thank you for your replies.
    I have been looking into it as well and seem to have found quite a simple solution...
    First you need to create an instance of a UIScrollView in the .h file:
    IBOutlet UIScrollView *scrollView;
    Then in the .m file, add the following line of code in the viewDidLoad method:
    scrollView.contentSize = CGSizeMake(320, 700);
    Then in IB all you need to do is set the files owner to the controller file we have set up above, drag a new instance of UIScrollView to the window. Then set two of its referencing objects to the File's Owner (view and the scrollView we have defined).
    You can then add as many labels etc to the scroll view by dragging in IB. Load it all up and the view scrolls perfectly and displays all labels!
    Thanks for helping me look into this.

  • Lightswitch html use the 'any' query method

    Hi
    Can someone please tell me how i can use the "any" query method for entity collections in lightswitch html?
    Thanks

    Hi Xpert360
    It's for a type of EntityCollection this is the code from the msls-2.5.2.vsdoc.js line 2220
    any: function any(predicate) {
    /// <summary>
    /// Determines whether this sequence contains any
    /// items that optionally satisfy a condition.
    /// </summary>
    /// <param name="predicate" type="Function" optional="true">
    /// A function to test each item for a condition.
    /// <br/>Signature: Boolean item.predicate(item)
    /// </param>
    /// <returns type="Boolean">
    /// True if this sequence contains any items that
    /// satisfy the condition, if any; otherwise, false.
    /// </returns>
    var result = false;
    this.each(function (item) {
    if (!predicate || predicate.call(item, item)) {
    result = true;
    return false;
    return true;
    return result;
    Check it out and let me know if you know how to use it, my problem is how to use the call back function.
    Thanks

  • How to get the tag of the User Defined Variables using the Get Tag method%3F

    For the cRIO modules under a cRIO Chasis, a tag value can be obtained using the Get Tag method with crio.Type to the TagName input of the method. When it comes to the User Defined Variables, what should be fed to the TagName input?

    For the cRIO modules under a cRIO Chasis, a tag value can be obtained using the Get Tag method with crio.Type to the TagName input of the method. When it comes to the User Defined Variables, what should be fed to the TagName input?

  • Problem in using the MBean.invoke() method

    I am using the method call:
    MBeanServer.invoke() which calls an appropriate method on the Remote MBean which is a synchronous call. However if the remote method takes longer than 5 seconds to execute, I get the following error
    javax.management.ReflectionException
         at org.jingle.jmxremote.server.RemoteDynamicMBean.invoke(RemoteDynamicMBean.java:317)
         at com.sun.jmx.mbeanserver.DynamicMetaDataImpl.invoke(Unknown Source)
         at com.sun.jmx.mbeanserver.MetaDataImpl.invoke(Unknown Source)
         at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(Unknown Source)
         at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(Unknown Source)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
         at java.lang.reflect.Method.invoke(Unknown Source)
         at com.sun.jmx.mbeanserver.StandardMetaDataImpl.invoke(Unknown Source)
         at com.sun.jmx.mbeanserver.MetaDataImpl.invoke(Unknown Source)
         at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(Unknown Source)
         at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(Unknown Source)
         at com.sun.jmx.remote.ws.server.actions.JMXInvokeManagedResourceOperationAP.processAction(JMXInvokeManagedResourceOperationAP.java:80)
         at javax.management.remote.ws.JMXManagementProcessor.processManagement(JMXManagementProcessor.java:268)
         at javax.management.remote.ws.JMXManagementProcessor.processManagement(JMXManagementProcessor.java:203)
         at javax.management.remote.ws.JMXServiceEndpoint.invoke(JMXServiceEndpoint.java:127)
         at javax.management.remote.ws.JMXServiceEndpoint.invoke(JMXServiceEndpoint.java:55)
         at com.sun.xml.ws.server.provider.ProviderPeptTie._invoke(ProviderPeptTie.java:63)
         at com.sun.xml.ws.protocol.soap.server.SOAPMessageDispatcher.invokeEndpoint(SOAPMessageDispatcher.java:278)
         at com.sun.xml.ws.protocol.soap.server.SOAPMessageDispatcher$SoapInvoker.invoke(SOAPMessageDispatcher.java:586)
         at com.sun.xml.ws.protocol.soap.server.SOAPMessageDispatcher.receive(SOAPMessageDispatcher.java:141)
         at com.sun.xml.ws.server.Tie.handle(Tie.java:88)
         at com.sun.xml.ws.transport.http.server.WSHttpHandler.process(WSHttpHandler.java:171)
         at com.sun.xml.ws.transport.http.server.WSHttpHandler.handleExchange(WSHttpHandler.java:119)
         at com.sun.xml.ws.transport.http.server.WSHttpHandler.handle(WSHttpHandler.java:95)
         at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:65)
         at sun.net.httpserver.AuthFilter.doFilter(AuthFilter.java:56)
         at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:68)
         at sun.net.httpserver.ServerImpl$Exchange.run(ServerImpl.java:513)
         at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
         at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.InterruptedException
         at org.jingle.jmxremote.server.ResultContainer.hasException(ResultContainer.java:89)
         at org.jingle.jmxremote.server.RemoteDynamicMBean.invoke(RemoteDynamicMBean.java:306)
         ... 35 more
    Could you please help me in resolving this issue:
    Is this 5 second time out configurable?
    Is there some way I can by pass this problem?

    jingle is an implementation of the jmx-remote interface.
    The jingle implementation allows you to create an proxy of the MBeanServer on the MBean side. So the MBeanServer methods can be called using this proxy object rather than the the MBeanServerConnection object.
    The reason i am using this proxy object is because i want to register the mbean to the remote mbean server.

  • How to migrate users, which have been using the Windows Authentication method

    Hi everybody,
    I have to migrate a productive SQL Server 2008 Database from one to another different server. The problem is that a lot of users have been using this DB throught the Windows Authentication method. Because the migration should be faster as possible, I would
    like to use a SQL script in order to streamline the process. Does anyone know if it is possible to do it?
    Thank you in advance,
    Regards

    Apart from transfer logins scripts Ashwin and Stan mentioned, I usually run following script in order to re-establish orphan users to establish if any SQL logins.
    set nocount on
    declare @username    sysname,
            @errcode     int
    select @errcode = 0
    select @username = min(name)
    from sysusers (nolock)
    where uid <> gid and
          name not in ('guest', 'sys', 'INFORMATION_SCHEMA') and
          suser_sname(sid) is null and
          issqlrole = 0
    while @username is not null
    begin
       if exists (select 1
                  from master.dbo.syslogins (nolock)
                  where name = @username)
       begin
          exec sp_change_users_login @Action = 'Update_One',
                                     @UserNamePattern = @username,
                                     @LoginName = @username
          select @errcode = @@error
          if @errcode = 0
             print 'The user ''' + @username + ''' was re-established in database!'
          else
             print 'Failed to re-establish user ''' + @username + ''' in database!'
       end
       else
       begin
          print 'The user ''' + @username + ''' does not have login ID. So, drop it from database!'
          exec sp_dropuser @username
       end
       select @username = min(name)
       from sysusers (nolock)
       where uid <> gid and
             name not in ('guest', 'sys', 'INFORMATION_SCHEMA') and
             suser_sname(sid) is null and
             issqlrole = 0 and
             name > @username
    end
    go

  • HT3986 Hi, i have a macbook pro version 10.6.8 with boot camp version 3.0.4. I managed to install windows 7 professional x64, however when i insert my OS CD to install the drivers using the boot camp method, it says unsupported to this computer model

    Hi, i have a macbook pro version 10.6.8 with boot camp version 3.0.4. I managed to install windows 7 professional x64 bits but however when i tried to install the drivers using the OSX MAC CD using boot camp, it prompt me boot camp x 64 is unsupported with this computer model. Then i tried the method by right click the bootcamp x64 and managed to install the drivers. However, i still couldnt manage access the internet and it prompts me no networking hardware detected...Any idea how can i solve it?
    P.S i tried updating my bootcamp version 3.0.4 in mac os with bootcamp x64 version 3.1 exe but it shows me weird wording..
    my bootcamp version in windows 7 is 2.1..

    Uninstall 2.x totally
    Use CCleaner Registry tool
    Do whatever you need to to nuke the existing Apple programs and folders hidden here and there also.
    BC 2.2 was XP and Vista only

  • How do I submit a form to a LC process using the process fields component in LC Designer

    I have a PDF Form with the Process Fields component attached.<br /><br />In the FSSubmit component, I have set the URL to <br />http://localhost:8080/soap/services/SAPS_Submission?wsdl, <br />where SAPS_Submission is the name of my process.<br /><br />I open the form through a Flex app, fill out the form and press submit, but get the following error:<br /><br />  <?xml version="1.0" encoding="utf-8" ?> <br />- <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><br />- <soapenv:Body><br />- <soapenv:Fault><br />  <faultcode xmlns:ns1="http://xml.apache.org/axis/">ns1:Client.NoSOAPAction</faultcode> <br />  <faultstring>no SOAPAction header!</faultstring> <br />- <detail><br />  <ns2:hostname xmlns:ns2="http://xml.apache.org/axis/">dtross</ns2:hostname> <br />  </detail><br />  </soapenv:Fault><br />  </soapenv:Body><br />  </soapenv:Envelope><br /><br />The LC process has the schema for the form as an input variable, which is used in the execution of a insertSQLStatement.<br /><br />My knowledge of the process fields component is sketchy at best, but from what I understand, I can use it to submit to workbench without using a servlet?<br /><br />Any help with getting the data from the form to the process using this technique, or clarification about what I should actually be doing would be greatly appreciated...<br /><br />Thanks<br /><br />Ross Malan

    The process fields are ONLY needed if you're planning to use the form offline or through email. If you submit the data back to a servlet, you just need to put a submit button on the form.
    Jasmin

  • How to use the VBS MoveFolder methode in DIAdem without any error message?

    Hi,
    I want to move folders with the VBS MoveFolder methode, but in DIAdem I run in problems. When I use the following comman    fso.MoveFolder(project_folder & test_folder, project_folder & test_folder & "\" & test_ & " " & test_count) 
    I get error message
    "During call a sub routine no parentheses are allowed!"
    When I remove the brackets and use    fso.MoveFolder project_folder & test_folder, project_folder & test_folder & "\" & test_ & " " & test_count 
    I get the error message
    "Invalid sub routine call."
    How I have to use the command right?
    (the text of error messages is free translated from German Version of DIAdem 11.0! Take only the sense, not the exact wording!)
    Thanks for help.
    Regards
    Sven

    Hello Sven!
    Just add a 'Call' at the beginning of your first line will solve the syntatic error. I recommend always to use 'Call' and parenthesis.
    But there is a fundamental problem in your code: MoveFolder moves a folder from a source to a new destination and the old source folder will be deleted. You try to move a folder to a location below the same folder. If the MoveFolder wouldn't recognize these situtation and throws an error all of your data would be deleted!
    Just print out your paths in a Messagebox to clearify the situation.
    Matthias
    Matthias Alleweldt
    Project Engineer / Projektingenieur
    Twigeater?  

  • Removing power lines using the Stroke path method

    I watched a video created by Adobe Product Manager Brian O. Hughes titled Adobe Max:  Hidden Gems in Photoshop an excellent video (see link below).  I have been trying his easy method of removing power lines from an image using the pen tool and stroke path method defined as follows:
    Using the pen tool create a path of the line to be removed.  Making sure the brush tool is small and set at 100% opacity;  click on the Spot Healing Brush making sure it is set to "content aware".  Then in the path panel click "stroke path" and it removes the line.
    Well I have followed these instructions several times, very simple, but it doesn't remove the line for me.  I can manually shift click the start and ending point and it removes it but using the stroke command within the path panel doesn't work.  I am making sure the path is active.
    Any ideas why it doesn't work for me?
    Thanks...........Ralph
    Here is the link to the video, his technique is listed near the end, @ minute 56:  http://www.youtube.com/user/Photoshop

    Hi jjMack, thanks for your response.  I found my problem after realizing that I hadn't terminated my pen line.  I didn't realize I had to click the end anchor point to complete the line,  I thought since the line was obvious on the image that it had been created and  thought I couldn't see it in the paths panel because it was so small (these old eyes aren't what they used to be).  When clicking on the last anchor point it could easily be seen on the paths panel..  I just don't use the pen tool enough so I didn't realize my error.  Learn something everyday.  Incidentally, I had set the stroke path on the paths panel to Spot Healing Brush and only used the tools menu to confirm that content aware was selected.
    Thanks again JJ................Ralph

  • When to use the "Process Fields"?

    Hi, I have a simple form with some text fields and a couple of Signature fields. 
    All is working fine in the WorkSpace.
    The Process / Workflow is also simple, Initiator --> User --> User.
    But I want the user to be able to submit the form outside of the WorkSpace.  ie. the user receives the form as an attachment to the Notification email from the server, user opens the attached PDF, clicks the submit button, and the workflow continues on to the next step after the server receives the email from the user.
    I read it somewhere that, in order to do this, I will need to drag the Process Fields block onto the form.
    So I did that.
    Before trying the email-submit, I wanted to make sure that it still works in the WorkSpace. 
    Unfortunately, it doesn't work anymore.
    When the "User" (2nd and 3rd steps in the workflow shown above) opens the workitem, the PDF form was not displayed in the browser, instead it's a XML page.
    So, my question is, what do I need to do in order to make the Process Fields work with my form? and the user can submit the form by email too.
    also, whatever changes I need to make, it won't break the Signatures.
    thanks

    Hi,
    Regarding field transfer, I answered your previous post.
    Regarding the project tree navigation, you can use function module 'BAPI_BUS2172_GET_TREE' (with the project guid as import parameter), and then sort the table Ascending or Descending.

  • ALV Tree list output using the Class and method

    Hi,
    How to get the internal table values of ALV Tree List in classes.
    My requirement is i need to store the output values in Ztable of a SAP Transaction of CK86_99.
    for this, i copied the SAP Standard Transaction into Z tcode and i am trying to poplulate the output display into Ztable. But this standard tcode CK86_99 is using the classes of ALV tree list to display output.
    CL_STRUCTURE_EXPLOSION_TREE -- Class
    CONSTRUCTOR - method
    Finally in the above mentioned method, i am able to see the output values of ALV tree list in the internal table of mt_output_table.
    But these are SAP Standard Class and method.
    My doubt is, How to get these internal table values in my Zprogram.
    is there any user exit or badi can we use in the method of class???? Actually my system is 4.6C
    Please suggest me on this problem.
    Thanks in advance
    KBS Reddy

    First your getInstance() method returns 'singleton' which you havent declared/init anywhere.
    your getAll() method needs to be static if you need to call it the way you are doing.
    In your getAll() method u are passing a parameter called patientRecord ... where have you declared/init it.
    i think you have to do something like this ... if i have understood you correctly.
    /* THIS IS IN YOUR SERVLET*/
    Collections c = database.getAll();
    out.println(C);
    /* YOUR FlatfileDatabase CLASS HAS SOMETHING LIKE THIS*/
    public static FlatfileDatabase getInstance() {
    return new FlatfileDatabase();
    public static Collections getAll() {

Maybe you are looking for