Beginner: how to manage the pipes and the semicolon with UNIX commands?

Good afternoon
I'm writing a Java class that allows to run UNIX commands.
Launch of the simple commands (to date, ps - ef) works fine, but when I start using of pipes and the semicolon, it won't:
Java (e.g. hoses) code:
        String command = "ps -ef | grep config";
        Process child = Runtime.getRuntime().exec(command);
Result:
usage: ps [ -aAdeflcjLPy ] [ -o format ] [ -t termlist ]
        [ -u userlist ] [ -U userlist ] [ -G grouplist ]
        [ -p proclist ] [ -g pgrplist ] [ -s sidlist ]
  'format' is one or more of:
        user ruser group rgroup uid ruid gid rgid pid ppid pgid sid taskid
        pri opri pcpu pmem vsz rss osz nice class time etime stime
        f s c lwp nlwp psr tty addr wchan fname comm args projid project
Code Java (example of semicolon):
        String command = "date;ps -ef";
        Process child = Runtime.getRuntime().exec(command);
Result:
date;ps: not found
Clearly the pipes and semicolons are managed by the UNIX shell and can be put in the Java source code as such.
Does anyone know a way around this?
Thank you
Dominique

Pipes and semicolons are interpreted by a shell (bash, csh, etc.) and when we execute as you do without shell is involved. It is easy to solve by using the alternative version of exec() which takes an array as an argument and use your shell of choice. For example: -.

String[] command = {"bash", "-c", "date;ps -ef"};

Note that the third argument is the entire order to be interpreted.

Two points to consider. First you need to read, Digest and apply all the recommendations in http://www.javaworld.com/jw-12-2000/jw-1229-traps.html; otherwise will be at some point lead to a significant loss of hair. Secondly, you should probably use ProcessBuilder rather than Runtime.exec (). Behind the scenes, Runtime.exec () uses ProcessBuilder but ProcessBuilder provides a better interface with more features.

Tags: Java

Similar Questions

  • How to manage the selection with the box in a table

    Hello


    JDev 11.1.2.4

    I have a table with an attribute of EO/VO, transitional to manage the selection. This attribute is displayed as a check box. The user makes a selection by clicking on the checkbox. Then, the user clicks on a button that displays a pop-up window. Inside of this pop-up window, that user can create, insert, delete, or update values in a table based on an other EO/VO.

    When the user clicks OK, the pop-up window is closed, then the data is committed.

    When the user clicks Cancel, the popup is closed and the changed data are ignored. To remove the data, I call a Rollback. It works fine, but all the transitory values are lost which is correct because of the discount after the cancellation.

    It's a problem because the user must be able to open the pop-up window several times with the same selection. This means that the restoration is not appropriate in this case.

    How to ignore data edited inside the pop-up window and keep the selection?

    Thank you

    You can try to put the popup in his own taskflow and define a backup point before entering the taskflow. When the user cancel the editing restore you to previous backup. This should dispel the changes.

    Or you save the selected rowkeys, call rollback and backward selection later.

    Timo

  • How to manage the Tags with PowerCli

    Hello

    I'm trying to find examples how to manage Customs 'Tags' in vSphere 5.1. This new feature is only used in the web client.

    I would like to create, delete, and associate tags with PowerCli objects.

    Is someone can tell me the basic commands?

    Thank you.

    Karl


    Currently, there are no PowerCLI cmdlets to manage the tags.

    But take a look at Create/Set TAGs via PowerCLI

  • How to manage the medium with #missing

    Hello everyone,

    I'm still pretty new to implement Calc and I'm trying to calculate balances average periods except when an intersection is #missing or 0.  For example, the following code works but is not the proper syntax and I was trying to find a way to improve it.

    DIFFICULTY (/ * SUN: scenario * / 'FcstDev' / * SUN: Version * / 'Final', / * SUN: cost Center * / "831")


    DIFFICULTY (& FcstYear1, & fcstPerStart: 'Dec')

    ("Securities taxable"
    IF (@ISMBR ("End") AND ("Taxable securities" is #Missing or 'Taxable securities' == 0))
    'Taxable securities values'-> 'Avg' = #Missing;
    ON THE OTHER
    "Taxable securities'-> 'Avg' = (@PRIOR ("securities of taxable"->"End") + (" taxable securities '->' end ')) / 2;
    ENDIF ;)

    ENDFIX

    ENDFIX

    I do not know how to handle my cross-dims 'Avg' is calculated based on 'end '.  Any suggestions would be greatly appreciated

    Thank you

    Bret

    fairytale watch functions @avgrange and @currmbrrange I think that will do what you want with less work than what you have coded

  • How to manage the server with a private ip address, which is NAT'd a routable ip address?

    Hello

    My display server has multiple servers that sit behind firewalls. The NAT firewall their ips to a private address space routable ip address. My problem is that I do not get a display of these servers. Firewalls are configured to allow tcp port 1984 to the display server. I ran a sniffer package on the source and the display server. I can see that the packets leave the source server and they hit the display server, however, nothing is displayed. BB-hosts, I have routable ip address. He made the ping and ssh test and reports those, but nothing else. I have private IP routable ip address in the security file. Any suggestions on what I may be missing?

    Kind regards

    Brad

    Hi Brad,

    If you can see the State of BB messages leaving your client machines, and you can see them coming in your BBDISPLAY server, then you can treat a case problem, or, perhaps your BB customers are defined with different names within your bb-hosts file.

    Check $BBVAR/logs on your BBServer for status messages files that look like they came from one of the BB clients that do not appear on your BBDISPLAY.

    If you can see the files of newspapers of status of these $BBVAR BB clients / newspapers my suspicions are correct. There is incompatibility between the BB customer name and the name of the customer in bb-hosts on your BB BBDISPLAY.

    Thank you
    Paul

  • How to manage the SOAP response

    Hello (beginner vCO),

    I use the SOAP Plugin and trying to figure out how to manage the here, a host of SOAP response is the log I get the SOAP response

    [12:53:43.124 2014-05-09] [I] the settings...

    [12:53:43.135 2014-05-09] [I] the available settings:

    [12:53:43.136 2014-05-09] [I] + parameter name: "GetRequestStatusResult", value: "< response >

    < item >

    < ServiceRequestID > SR138917 < / ServiceRequestID >

    OS DEPLOYMENT < ServiceRequestStatus > < / ServiceRequestStatus >

    < ServiceRequestCreated > 09/05/2014-15:20:25 < / ServiceRequestCreated >

    < ServiceRequestCompleted > < / ServiceRequestCompleted >

    MA138921 < CurrentActivity > < / CurrentActivity >

    OS DEPLOYMENT < CurrentActivityTitle > < / CurrentActivityTitle >

    < ActivityStartUTC > 09/05/2014-15:32 < / ActivityStartUTC >

    < ActivityEndUTC > < / ActivityEndUTC >

    < DurationTotalSeconds > < / DurationTotalSeconds >

    < AverageDurationSeconds > < / AverageDurationSeconds >

    < SecondsOffAverage > < / SecondsOffAverage >

    < EstimatedCompletionUTC > < / EstimatedCompletionUTC >

    < / OutputParameters >

    < warning > < / warnings >

    < exceptions > < / Exceptions >

    < / response > '

    It will be better to try and parse text or try and use another method with vCO

    If you haven't done so already, take a look at the action of com.vmware.libarary.soap.processOutParameters.  It is the action that generated the log you have placed in us.  It generates an object Properties (key, value pairs) with the value for each setting that results.

    In your case, assuming that 'outProps' is the result of the above, you can use:

    var getRequestStatusResult = outProps.get ("GetRequestStatusResult");

    And to analyze the code XML with E4X as Ilian said.

  • I would like to know how to manage the ASN.1 encoding/decoding in LabView?

    I would like to know how to manage the ASN.1 encoding/decoding in LabView?

    Hello J,

    in the example given here , it looks like a format simple bytestream...

    You must read the byte stream, get the first and the second byte to decode the data type and length and then read & catalogued according to number of bytes. And then read 2 bytes and so on...

    Encoding will work the same but in reverse

  • How to manage the tv after hdmi to hdmi connection

    I want to connect to my computer windows 7 with tv on my Vizio tv hd tuner. I intend to use the hdmi to hdmi connections. After that I made the connection how to manage the tv without going back to the computer. My TV is in another adjacent room to my computer, sbout 20 ft away. Can I use a wireless mouse to manage the tv? The monitor and tv both appear at the same time? What are other options? Thank you for taking my question and to meet others, I put in the forum. Donnie

    I guess that the xbox 360 is a must for my setup. Thanks for your reply, Donnie

  • Windows 8.1 in Adobe Illustrator, I tried to copy my design &amp; tried to paste it, but after sticking the image (file), now the color looks different, drive and lighter. So, kindly inform how to paste the file with 100% same resolution / color / appeara

    Windows 8.1 in Adobe Illustrator, I tried to copy my design & tried to paste it, but after sticking the image (file), now the color looks different, drive and lighter. So, kindly inform how to paste the file with 100% same resolution / color / appearance. Thank you.

    Hi GANESHKUMARAPILLAI CHRYSTELLE,.

    Here is a link for color management workflows in Illustrator.

    It is best to place the image instead of paste into Illustrator. When you paste the images they are in RGB color format. Make sure your document is a RGB file

    Click on these links for more information.

    Understand the workflow of the CC of individual course Illustrator color management: Advanced

    Creative Suite * keeping colors consistent

    Implement the print color management workflow. Illustrator, InDesign, Photoshop

    Concerning

    Scott

  • How to manage the photos Lightroom when using 2 computers, keeping any changes made on one or the other?

    Based on http://forums.Adobe.com/thread/1308132?TSTART=0 I decided to add each question separately:

    Hello, I am very interested in buying Lightroom 5.2. I tried the RC that was missing today. Yet, I have several questions that I can't find really good conclusive answers, I'd like to get an answer before buying LR. Please do not write maybe like this or that (assumptions), because I don't want to start my entire workflow and then realize that I have to change all around, please reply, if you know for sure that something works and you are, preferably, using this method too.

    Is the big question, where I want to especially a conclusive answer:  How to manage the photos Lightroom when using 2 computers, keeping all the changes made on one of them, using the same photos for editing. I'm not going to use DNG. Details: I mainly use my old MacBook Pro, but I wish I could use my PC as it is much better (card: i5 2500K, 16 GB of RAM, SSD, USB3, nVidia GTX 560 TI etc.). I have 2 external HD that I could use, one for backup and one for the actual Photos/changes. I you will probably need to use as my internal HDs are fairly complete and I cannot be the kind of things simply delete or move to one (developer, without loss of music, programs etc.).

    On this basis, how do I save all such Photos folder (pictures and retouching and preferably presets too)?

    According to me, that it should be possible to work cross-platform without having to create a link to the files each time, or without having to keep export/import of the catalog, keeping the single catalog and the picture library on an external drive that is then switched between systems as needed.

    Obvious first requirement is an external drive that is formatted in a way (for example, FAT32) that it can be used on both platforms in read/write mode. Given that, if the catalogue AND folder parent si le catalogue ET le dossier parent images are both set to the same level in a global parent folder, then it should be possible to take advatage of ability of Lightroom to use relative paths instead of absolute paths to detect the images, no matter if the player is named (Mac) or lettering (PC). This is how "export as catalog of ' works, that is, it creates a 'package', alias a parent folder, containing the catalog and a replica of the folder hierarchy to exported along with the catalog images. Take this 'package' to another system (same OS or not) and "it works" even if the drive letter is different or the operating system is different... because the relative path of the image catalogue is always the same.

    I have not tested this cross-platform (if I have between various PC systems with letters of different readers) so for me it's still just a theory, but there may be others who have done this successfully.

  • How to manage users of Lightroom photo sharing with the family?

    I'm looking for some best practices on how to manage the workflow of photo sharing.  Obviously the user of Lightroom does not want family members to start messing around with photos outside of Lightroom, and if the photos are not JPGs family members may be unable to view them in any case.  A solution I can think of is to shoot photos in JPG format and in Camera Raw at the same time and save the jpg files in a folder accessible to all and only import Camera Raw ones in Lightroom.

    Flickr works as well.

  • How to solve the problem with the wacom tablet and the polygonal lasso tool. It does not work with a pen.

    How to solve the problem with the wacom tablet and the polygonal lasso tool. It does not work with a pen. I have install windows 10 and fresh, new drivers for wacom bamboo, could he makes problems or there is a problem of photoshop?

    It should do.  You use one of the buttons of pen maybe?  Just touching wheels with the pen with no buttons or modifier keys.  Press ENTER to close the selection.

    Personally I never use the lasso, Polygonal, but rather just the Lasso tool by using the ALT (Opt) to operate the Polygonal tool.  I also use the mouse instead of the Tablet for the selection of cutting edge.  It is a little too uncertain where the point will go when hovering the stylus above the image.

  • How to sample the color with the eyedropper tool and have it be the foreground color?

    How to sample the color with the eyedropper tool and have it be the foreground color?

    Use the keyboard shortcut to set the default foreground sample.

    The sample of foreground (top left in the screen shot) is visible and you just click on the color with the eyedropper tool to change.

    You can also use x to exchange the undertone in the foreground if you want to change that.

  • How to remove the old drivers (hidden) command line?

    Hello

    I want to try to remove all the hidden command prompt devices. There is a way to this topic?

    For example;

    type driverquery on cmd and sort all the lists of hidden devices

    After that type Remove any device (for example) and remove this hidden device

    Thank you.

    Enbiya salvation,

    Thanks for posting in the Microsoft Community.

    You can manually remove hidden devices by following the steps below.

    1. press the key Windows + X key, then select "Device Manager".

    2. from there, select the view > show hidden devices.

    3. now, select the hidden device > right click and select "Uninstall" to permanently delete or 'Disable' to disable the device.

    To find the command prompt commands and settings command line of how to do the same with the command prompt, you can follow the link below and check if it helps.

    Windows Device Console (Devcon.exe)

    https://msdn.Microsoft.com/en-us/library/Windows/hardware/ff544707 (v = vs. 85) .aspx

    Please let us know if the problem is resolved or you need additional assistance.

  • How to fix the error with the code: 0xe7210001 failed to load powrprof, object: cls

    Hello

    Dose anyone know how to fix the error with the code: 0xe7210001, message: unable to load powrprof, object: CLSD-no-it is found;
    OR: Fingerprintsoftware OR error: replicas THotkey.exe message window and the computer freezes

    Maleware scanned and virus, also in safe mode, found no infection, reinstalled driver fingerprint, but nothing has changed.

    grateful for the help!

    Hello

    > message: unable to load powrprof, object: CLSD-no-it is found;
    In my view, this would mean that there is a problem with Toshiba Power Saver
    What laptop Toshiba, you have exactly?

    Maybe reinstall Power Saver could help. You can find it on the official website of Toshiba.

Maybe you are looking for

  • FF4 - when bookmarking a Web page, "Select" shows only 5 of my bookmark folders

    I have a new laptop Acer 5745 G computer. Three guesses are correct, not sure about NPWLPG I recently went from FF3.6 to FF4. To bookmark a webpage, I rt clik/bookmark this page/Choose/. Only 5 (randomly selected?) folders appear. There is no scroll

  • My HP1022 prints but ends with flashing lights

    Hi everyone... my Mono HP Laserjet 1022 began flashing at the end of each test and so must be reset each time by cutting, turn everything now pressed both keys and releasing those when the flash sequence changes. It then prints on the next click-to-p

  • Need to replace hard dv7 Pavilion

    HP Pavilion dv7 Notebook ID system 363C Product ID NQ559AV I7 CPU Q820 Version of the BIOS F.1D Serial No. [number of Series edited by Moderator] My hard drive seems to have failed.  Run the HP hard drive Test in BIOs from HP SMART Check passed DST s

  • Change the camera menu items

    Hi all I invoke the camera of my application. I want to remove a few menu items that is provided by the camera application. How to do this. Thank you very much

  • BlackBerry smartphones reload software 552

    Hello I just bought a blackberry curve 8520 a week ago and everything worked well, until I tried to uninstall a free app I install appworld, it asked me to reboot. So I did and when restarting blackberry I had this on my screen "reload software 552.