Redirect standard input from file to terminal

Is there any way to redirect standard input from file to terminal within the same program? That is, get data from a file then redirect standard input to make it interactive with the terminal?

BIJ001 wrote:
No, the stdin, stderr, stdout, and working directory are environmental variables that are set
when your process is launched, and they cannot be changed from within your java application.Can't they?
//java.lang.System
public static void setIn(InputStream in)
//   Reassigns the "standard" input stream.
public static void setOut(PrintStream out)
//  Reassigns the "standard" output stream.
public static void setErr(PrintStream err)
//  Reassigns the "standard" error output stream.
Since:
JDK1.1
Duh, you're right. I researched this looking for a way to change the working directory and found that you could not change that after launch - for some reason I remembered it wrong as being the stderr, stdin, and stdout in addition.

Similar Messages

  • Redirecting standard input

    Can I redirect std input using a tee to both a file and std output without loosing the prompt? I am trying to build a simple keystroke logger. I am only unsure of how to reference all things passing through std input. I can redirect an echo statement for example, but how to do it on a larger scale is the question.
    thanks for the time.

    Hi Daniel,
       It's hardly clear what you mean by redirect. What the shell does with input is written in C and I don't really how that's done.
       However, I do know how to emulate that in a shell script. Whenever you invoke a command that's not in a pipe, subsequent input to the shell is provided to the command. When the command is a shell script, it can access that via the "read" command.
       The "read" command is invoked with at least one variable as an argument and you can also specify a prompt that is printed to screen. When invoked with a single variable argument, whatever the user types is echoed to the command line and stored in the variable when the user hits the <Return> key. Of course you can also specify a number of keystrokes and that number of characters will be stored in the variable as soon as they are typed.
       As I said, more than one variable can be provided as arguments to the "read" command but that's an advanced lesson. You can read the details in the description of the "read" command in the "SHELL BUILTIN COMMANDS" section of the bash manpage.
    Gary
    ~~~~
       She sells cshs by the cshore.

  • Setting up position of front panel objects using input from file

    I am working on a project and i have got the following query.
    i have a front panel with lot of objects like knobs,dials,push buttons etc..
    the entire panel will be the console to the user and as he changes the various
    positions of the objects their values will be written in to a file.
    now after a days work when the system is restarted again the next day
    the values of various objects should be read from the file and the front panel objects should be set in their position according to it
    in short the objects(knobs,buttons etc) should both act as o/p i.e when user interacts with them and they should also act as i/p when their position will be set from
    file.
    how can i achieve this.any help regard
    ing this would be greatly appreciated

    You should separate the read portion of this vi from the write portion of the vi. You want to execute the read portion of the vi only at startup and the write portion of the vi only at shutdown. So you'll be reading the file and writing the output to the property nodes, running your program, and then taking the value of the controls and writing to file. I have attached an example of how this might work. You might also do this with a state machine structure to control the data flow.
    Hope that helps
    Attachments:
    query.vi ‏49 KB
    read_file.vi ‏42 KB
    write_file.vi ‏36 KB

  • Scanner Input from File

    I'm trying to read from an external file using the Scanner class and to store the input in the applicable arrays, but I don't know how to skip lines.
    For example, if a text file has this in it:
    Name: Bob
    Age: 30
    Job: Engineer
    Name: Joe
    Age: 40
    Job: ManagerIt reads fine, and stores fine. But, if I have this instead:
    Name: Bob
    Age: 30
    Job: Engineer
    Name: Joe
    Age: 40
    Job: ManagerWith the empty line, the String class throws an index out of range exception. Same goes for if the very first line of the file is also blank.
    Here is my code:
    String[] name = new String[100];
    int[] age = new int[1000];
    String[] job= new String[1000];
         try {
                  Scanner input = new Scanner(new BufferedReader(new FileReader("test.txt")));
                  for (int i = 0; input.hasNext(); i++) {
                       name[i] = input.nextLine().substring(6);
                       age[i] = Integer.parseInt(input.nextLine().substring(5));
                       job[i] = input.nextLine().substring(5);
                       System.out.println("Name: " + name);
                   System.out.println("Age: " + age[i]);
                   System.out.println("Job: " + job[i]);
              input.close();
         } catch (FileNotFoundException error) {}Thank you all very much!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    I already have something else that is handling non-existent files, so I don't need to do anything there.
    And thank you very much, I figured out how to do it! I just needed to temporarily store the line, see if it was longer than 1 in length, and perform based on that.
    Thank you very much!
    Edited by: ManiKatti on Dec 31, 2009 7:14 PM

  • Follow Up to Scanner Input from File

    Alright, I have another problem. My code is this:
    for (int j = 0; j < username.length; j++) {
         String line = input.nextLine();          // Create a temporary String that will store each line
         // Check if the temporary line isn't empty
         if (line.length() > 1) {
                 numAccounts++;
                 username[j] = line.substring(10);
                 password[j] = input.nextLine().substring(10);
                 System.out.println(username[j]);
         } else {     // If the temporary line is empty, go back on the loop to prevent empty array entries
                  j--; }
         }It runs through once, and then stops. Here are the declarations:
    static int numAccounts = 1;
    static String[] username = new String[numAccounts];
    static String[] password = new String[numAccounts];
    static  Scanner input = new Scanner(new BufferedReader(new FileReader("account.txt")));Which was done outside of the main method.
    Why does the loop iterate only once?

    Woah, don't need to get all heated up about something I'm doing wrong. I'm just trying to figure this out. Sorry if I'm getting on your nerves.
    So anyways, I did the ArrayList method with your suggestion of making it an ArrayList of Objects. This is what I have so far:
    // Declare the ArrayList that will store all the Account Objects retrieved from the database
    static ArrayList<Account> accounts = new ArrayList<Account>();
    while (input.hasNextLine()) {
        String line = input.nextLine();          // Create a temporary String that will store each line
        // Check if the temporary line isn't empty
        if (line.length() > 0) {
             //System.out.println(line);
             String currentName = line.substring(10);
             String currentPass = input.nextLine().substring(10);
             Account current = new Account(currentName, currentPass);
             accounts.add(current);
    }Yes, I stuck with using the line.length() > 0, because trying to use line != null doesn't work properly for me. Not entirely sure why. Just throws IndexOutOfBoundsException when it's called.
    And my Account Object class is as so:
    class Account {
         static String username, password;
         Account(String username, String password) {
              this.username = username;
              this.password = password; }
    }I tried to print out the username and passwords to the indexes of 0, 1, and 2, and they're all the same.
    System.out.println(accounts.get(0).username);
    System.out.println(accounts.get(0).password);
    System.out.println(accounts.get(1).username);
    System.out.println(accounts.get(1).password);
    System.out.println(accounts.get(2).username);
    System.out.println(accounts.get(2).password);What is also interesting, is that it only fetched (or copied) the last two lines in the text document. It ignores all the entries before that.
    Do you know what I did wrong? I think I did a logic error in there somewhere.

  • Remove  "  from file

    Hallow Im doing a batch input from file csv (comma dilmeted) In the file I have company that ok and company name with before and after the company name word <b>''</b>    how can I get rid of  from that . just<b> ''</b> before and after the company name .
    *--table with data from file(csv)--
      LOOP AT itab1.
        SPLIT itab1 AT ',' INTO:
           itab-osek_morsh
           <b>itab-company_name</b>
           itab-company_code.
        APPEND itab.
      ENDLOOP.

    Hi Antonio ,
    Now what i understand is that some companies may have " at begining , some may have at end , some may have both and some none .
    So your requirement is that if there is a " as the first char or last then we need remove it , for all other cases it is not required.
    If my understanding is correct , here is the code which gives the desired result
    * Selection Screen
    parameters : p_string type string .
    start-of-selection.
    DATA : t_result type  MATCH_RESULT_TAB. " Internal table
    data : v_string type i .
    v_string = strlen( p_string ).   " Get the lenght of string
    * get the offset of all occurances of " in your string
    FIND ALL OCCURRENCES OF '"' IN P_STRING RESULTS T_RESULT.
    v_string = v_string - 1.  " Here the offset start with zero
    * Check if last char is "
    read table t_result with key OFFSET = v_string transporting NO FIELDS .
    if sy-subrc = 0.
    " If yes remove if from string
    p_string = p_string+0(v_string).
    endif.
    *Check if the first char is "
    read table t_result with key OFFSET = '0' transporting NO FIELDS .
    if sy-subrc = 0.
    * if yes replace with space
      replace '"' in p_string with ' '
    endif.
    Check if this serves your purpose , if not please tell what is the concern you have.
    Thanks
    Arun

  • Standard input - main(String[] args) -- how?

    In eclipse, how do I feed the main with values?
    public static void main(String[] args) {
           System.out.println("Enter value: ");
           args =
        if (args.length != 1) {
    ...Thanks,
    george

    You mean basically command line arguments?
    Look in the run menu. For every run event there's a form that specifies how to invoke the program. Somewhere in there you can specifiy the command line arguments. I can't recall right now but I can look it up if you can't find it.
    Standard input is a completely different thing from command line arguments. Standard input, from the java point of view, is what comes in on System.in.

  • Getting input from a file(user I/O redirection)

    alright i am stuck on this program. Heres what i have to do
    I have to write a program usinbg arrays and looping. The program should get its input from a file (user I/O redirection). The first number in the file will be the number of numbers that follow to find the average of (maximum of 100) and print if they are above or below the average.
    I have called the program lab9.java. I already made a file called lab9.dat. This is whats inside the lab9.dat file.
    16
    15
    751
    24
    -56
    81
    227
    54
    99
    0
    102
    57
    58
    43
    245
    47
    73
    16 is how many numbers i am using.
    I am just stuck on how i should do this.
    I have to have the program look at those numbers from that file and then calculates the average and then it has to look at each individual number and print out if that number is above or below average. First off im getting an error when i put in java lab9 < lab9.dat. Am i messing up somewhere.
    I also have the loop:
    int numnums = cisio.GetInt();
    double nums[] = new double[numnums];
    int k;
    for(k=0;k<numnums;k++)
    nums[k]=cisio.GetInt();
    This is where im stuck. I need the program to get the average of the numbers and then compare each number to the average and say if its above or below average. I dont know how to do that. If someone can help me out that would be great.

    Yes, you would need three loops: one to get the input, other the calculate the sum, and a third to print out what numbers are less than and what more than the average. That is the easiest thing to do. It's possible to combine getting the input and calculating the sum in one single loop though. I'm glad you got it working! :)

  • BR0255W Cannot read from standard input during a dbverify

    Hello,
    I am using:
    BRBACKUP 7.20 (13)
    SunOS 5.10 Generic_144488-06 sun4u
    701 SAPSR3
    Oracle 11.2.0,.2
    brbackup -w only_dbv -t online -c -u / -e 16
    It generally runs ok, but today I got:
    BR0280I BRBACKUP time stamp: 2011-04-20 11.20.47
    BR0063I 5 of 11 files processed - 14900.039 of 73640.086 MB done
    BR0204I Percentage done: 20.23%, estimated end time: 12:45
    BR0001I **********________________________________________
    BR0280I BRBACKUP time stamp: 2011-04-20 11.21.44
    BR0281W BRBACKUP interrupted by signal 2
    BR0269W Wait situation interrupted - probably cannot continue
    BR0280I BRBACKUP time stamp: 2011-04-20 11.21.44
    BR0256I Enter 'c[ont]' to continue, 's[top]' to cancel BRBACKUP:
    BR0280I BRBACKUP time stamp: 2011-04-20 11.21.45
    BR0251W Function gets() failed at location BrConfEnter-1
    BR0253W errno 5: I/O error
    BR0255W Cannot read from standard input
    BR0280I BRBACKUP time stamp: 2011-04-20 11.21.45
    BR0261E BRBACKUP cancelled by signal 2
    BR0056I End of database backup: befrzrsn.dbv 2011-04-20 11.21.46
    BR0280I BRBACKUP time stamp: 2011-04-20 11.21.49
    BR0054I BRBACKUP terminated with errors
    1. Would you know what yould cause this Cannot read from standard input?
    2. Is there a maximum number of process that can/should be passed to -e option?
    Thanks in advance for your answer.

    Hello Benoît,
    if I understood correctly, your brbackup was not started interactively, but in background, by crontab or DB13 or something like that.
    As you perhaps know, signal 2 usually means that the process was interrupted by a ctrl-C from keyboard. This should not happen for a background process.
    It could be that someone played around with kill command.
    I rather suspect some resource bottleneck.
    Could you please check Unix kernel parameters (or whatever their equivalent in SunOS is called - I am not familiar with it).
    Or any suspicious entries in Unix log files?
    regards

  • BRGUI: Connect WindowsXP to AIX: BR0255E Cannot read from standard input

    Hi,
    I configure brgui.properties and seam everything ok:
    brgui.remote-0=D11 (rsh aixd11 -l orad11)
    It connect to server, but in the footer of 2nd BRGUI screen (after login screen) it appears "Error: Cannot read from standard input" in red.
    And some seconds later the application closes.
    I see the log and it has the following:
    BR0651I BRTOOLS 7.00 (16)
    BR0280I BRTOOLS time stamp: 2008-04-15 16.30.10
    BR0656I Choice menu 1 - please make a selection
    BR*Tools main menu
    1 = Instance management
    2 - Space management
    3 - Segment management
    4 - Backup and database copy
    5 - Restore and recovery
    6 - Check and verification
    7 - Database statistics
    8 - Additional functions
    9 - Exit program
    Standard keys: c - cont, b - back, s - stop, r - refr, h - help
    BR0662I Enter your choice:
    BR0280I BRTOOLS time stamp: 2008-04-15 16.30.10
    BR0255E Cannot read from standard input
    BR0280I BRTOOLS time stamp: 2008-04-15 16.30.10
    BR0654I BRTOOLS terminated with errors
    Can anybody help? Maybe is it related with AIX files authorizations?
    Thanks a lot!
    Rui

    Hi Rui,
    Please take note on the following important points.
    When you use the remote option, ensure that the environment on the
    remote host is fully configured to use the BR*Tools, and that the remoteuser has the relevant database rights. You should also ensure that the
    relevant environment files are actually called up during the remote
    access.
    and
    In some cases, BrGui does not work with the Remote Shell rsh from from
    Microsoft Windows XP Service Pack 2 or Microsoft Windows Server 2003
    Service Pack 1. See Microsoft Support Article ID 896336. Microsoft
    offers a hotfix for this purpose. As a workaround, use the rsh from the
    previous Service Pack. This is located in the uninstall directory after
    the Service Pack has been installed. You can also enter the complete
    path in the relevant remote call.
    Hope the above information helps.

  • Is there an easy way to run an Ajax function from input type=file to test the file name in DB?

    I've had the <input type="file">  ... <cffile ...> thing going for a few years now. 
    There is a database where the uploaded file names are stored once the files are uploaded to the server.  It sees things in terms of problems and stores uploaded file name accordingly with the ProbID prepended onto the file name; e.g., MyPicture.jpg would end up in the designated directory and databawe as P416_MyPicture.jpg.  This allows user to store pictures with the same name in different problems without a conflict.  There has been an issue with certain characters (e.g., spaces, +, #, etc.) causing problems when they are in file names so we have come up with a way using the <cffile ... rename> to replace these chars with _.  This means that MyPic+.jpg would end up being P416_MyPic_.jpg. 
         This is where the problem appears.  If someone were to upload MyPic+.jpg after someone else uploaded MyPic_.jpg in the same problem, then the + file would overwrite the _ file before the system knew they had a problem.  And there is now way to restore the original file without going to the system backup and doing so – which is a whole other story … especially, if the person doesn’t tell anyone.
         The logical solution would be to be able to test the new final file name (the name after making the substitutions mentioned above) against the existing files in the database before you went from the page where the <input type=file> control to the associated _action.cfm page where the <cffile> object is located.  Given that this seems to be the province of Ajax, this would seem like a natural use of the really interesting technology.  I have can determine the file name from the onChange action on the <input type=File> so that this would be the place for Ajax to come to the rescue by looking up the final file name and then letting the user know whether the resultant name is a unique within the database or not.  If so, I'll just enable the Add button which sets right next to the <input > control and let them upload it.  If not, I'll put up an error message telling them that this file already exists in the system.
         This would be the perfect solution.  It would let me do some Ajax stuff like I've wanted to do for the past year, but never have had the time to do because this is the project that won't go away.  This is, in fact, the last thing of any consequence that remains to do on this 2-1/2 year nightmare – be careful what you wish for.  If I can get this done this week, then maybe I can finally take a weekend off … maybe it will finally come to an end.
         Which finally leads to my question:  I'm looking for some tips on how to get this thing going since I can barely spell Ajax.  I've got a book and looked at some stuff online about CF and Ajax, but a good example or two or three would be worth a day's worth of poking around on the web and in my books.
         Thanks in advance for any suggestions, ideas, help, whatever.
    Len

    Adam,
         Thank you for your suggestion, but, after spending the night working with Ben Forta's CF8, vol 2, Chap 34, working with <cfajaxproxy>, I was able to do exactly what I wanted and it appears, after some testing, to work exactly as I had envisoned it should. 
         I am now calling a JavaScript function (testFileName) from the onChage event on the <input type="file"> or Browse button, which calls my proxy.cfc that contains the server side of the equation.  This funciton testFileName (I've run out of cleaver function/file names).  The query contained therein hits the database to see if the passed in parameters can pull up an existing file.  If they do, the particulars (file name, data attahced, etc.) are returned to the JavaScipt procedure that puts up the error notice.  The user can then chose to either overwrite the file or quit.  Quiting leaves the your on the Attachment PopUp where he/she started with nothing being uploaded. 
         Thanks again for your suggestion.  I appreciate your taking the time to do so.
    Len

  • From browse button of input type=file, can I show the content of a file

    Hi all,
    I am using, input type=file, where browse button appears. I am having a text area. My requirement is after I select the browse button, I need to show the content of the file in the text area. As of now I 've handled by having another button 'show', which should be pressed after browse done. But, How to handle it in the browse button itself, how will I get that action event from browse button. Plz help.
    Regards,
    Sam

    I think someone asked a very similar question here,
    http://forum.java.sun.com/thread.jsp?forum=45&thread=501889
    check the thread, it may help you.
    -S-

  • Cannot find file I'm trying to input from

    I created a small text file called "Trial.txt" and tried inputting from it, but always got a runtime error saying the file cannot be found. Here's the relative code, but I'm not sure how I can identify the file.
    File inputFile = new File("Trial.txt");
    FileReader in = new FileReader(inputFile);
    StreamTokenizer LetterFilter = new StreamTokenizer(in);

    Problem solved. ;) Thanks for everyone who was willing to help!

  • User Input from Text File

    Hello
    I would like to incorporate code into this to allow the script I found on the internet to pull input from a txt file and then wait for the script to end before using the next entry in the text file and run until all entries in the text file have been used.
    Any help would be great thx.
    Jason
    ' Get Options from user
    GetOptions
    If (bInvalidArgument) Then
        WScript.Echo "Invalid Arguments" & VbCrLf
        bDisplayHelp = True
    End If
    If (bDisplayHelp) Then
        DisplayHelp
    Else
        If (bCheckVersion) Then
            CheckVersion
        End If
        If (strComputer = "") Then
            strComputer = InputBox("What Computer do you want to document (default=localhost)","Select Target",".")
        End If
        If (strComputer <> "") Then
            ' Run the GatherWMIInformation() function and return the status
            ' to errGatherInformation, if the function fails then the
            ' rest is skipped. The same applies to GatherRegInformation
            ' if it is successful we place the information in a
            ' new word document
            errGatherWMIInformation = GatherWMIInformation()
            If (errGatherWMIInformation) Then
                If (bDoRegistryCheck) Then
                    errGatherRegInformation = GatherRegInformation
                End If
                GetWMIProviderList
            Else
                WScript.Quit(999)
            End If
            If (bHasMicrosoftIISv2) Then ' Does the system have the WMI IIS Provider
                GatherIISInformation
            End If
            SystemRolesSet
            If (errGatherWMIInformation) Then
                Select Case strExportFormat
                    Case "word"
                        PopulateWordfile
                    Case "xml"
                        PopulateXMLFile
                End Select
            End If
        End If
    End If

    Unfortunately the script is too long to be posted but can be found at
    http://sydiproject.com/download/and is called Server v.2.3. I have also contacted the author and made the suggestion I
    asked about.
    Jason
    I do not know which script you had in mind but the one I looked at had 1,600 lines of code. As you say, posting it here would be inappropriate. At the same time it is unrealistic to ask for help for such a large script. Asking the author is one option. The
    other option would be to identify the module you wish to modify, analyse it until you fully understand it, modify it so that you can run it in a stand-alone manner, then post your question here. You will probably find that you can answer the question yourself
    after analysing the code!

  • Get input from user and create a file and run a script in command line.

    Hi all,
    i'm trying to get a input from user and write it into a file named alpe.jacl
    To get multiple userinputs like address and jobtitle etc etc in the same single window.
    and the code will save the inputs in alpe.jacl one by one in a new line like
    nameis name
    address russia
    jobtitle dev
    So i coded like below.
    Though GUI for user input looks dull Its working fine.
    Now I want this code to perform one more task which is the GUI will contain one more button INSTALL with OK and CALCEL .
    and when after putting all inputs and creating the alpe.jacl file if someone clicks INSTALL it should start ./install.sh script present at the same folder which contains some unix shell commands.
    Here am not able to figure out how to go further...
    One more thing after all the inputs given when I am clicking on the OK button its closing the window instantly which i dont want. I want it like it should wait till someone press CANCEL to exit.
    Please some one help me.
    import javax.swing.*;
    import java.io.*;
    public class file
    public static void main(String []args)throws IOException
    FileWriter ryt=new FileWriter("alpe.jacl");
    BufferedWriter out=new BufferedWriter(ryt);
    JTextField wsName = new JTextField();
    JTextField sName = new JTextField();
    JTextField cName = new JTextField();
    Object[] message = {    "Web Server Name:", wsName,"Server Name:", sName,"Cluster Name:", cName};
    int answer = JOptionPane.showConfirmDialog(    null, message, "Enter values", JOptionPane.OK_CANCEL_OPTION);
    if (answer == JOptionPane.OK_OPTION){    String webserver = wsName.getText();
    String server = sName.getText();
    String cluster = cName.getText();
    out.write("set webservername " +wsName.getText()+"\n");
    out.write("set ClusterName " +cName.getText()+"\n");
    out.write("set ServerName " +sName.getText()+"\n");
    out.close();
    }}Thanks,
    Ricky

    Thanks a lot.
    Is there any way through which i can assign a scroll bar to my panel.
    As when the number of user inputs grows the GUI becomes more bulky and some of the fields are not showing up.
    Cheers
    _Ricky                                                                                                                                                                                                                                                                                                                                                                                                                                   

Maybe you are looking for

  • ITunes library does not show up on second hardrive

    I upgrade to Tiger on an external hardrive, when I launch iTunes, none of my music is there. Do I need to move the music folder to the external hardrive, or is there a way to have iTunes find the music from the main drive? Thanks, Jim

  • Error while deploying app on Tomcat 6.0

    Hi All, As per https://blogs.oracle.com/dana/entry/how_to_deploy_a_11g_adf_applic_1 , I tried to deploy ADF web app on Tomcat 6.0, but I was blocked by following errors. Env: Jdev 11.1.1.6.0 Tomcat 6.0.36 Catalina.log 2013-4-16 10:29:58 oracle.adf.mb

  • Could not complete your request

    Receiving message could not complete your request because photoshop does not recognize this type of file. My wife just installed mavericks and updated to flash 11. When we try to bring a photo into pse 12 . We receive the above message. We are trying

  • No javaw in jrockit-jdk1.6.0_33-R28.2.4-4.1.0

    Hi i am trying to use the jrockit jvm for my eclipse. The documentations tells me that i have to point to javaw as the jvm in the eclipse.ini file. I have installed jrockit-jdk1.6.0_33-R28.2.4-4.1.0 and jrockit-jdk1.6.0_37-R28.2.5-4.1.0 on my oracle

  • Synchronizing calendars and contacts using 2 computers and 2 iphones

    my husband and I both have a MacBook Pro; we both have an iPhone. Lucky us! We want to be able to synchronize our calendars and contacts on each other's computers. How can we do this without over-writing each other's calendars and address book? We bo