Path: csiph.com!aioe.org!.POSTED.D/yWLgg4/J3ZIv1oe1tc3Q.user.gioia.aioe.org!not-for-mail From: "Dr.UgoGagliardelli" Newsgroups: it.comp.java Subject: Re: comandi Bash su Mac da Java Date: Fri, 30 Aug 2019 16:43:21 +0200 Organization: Aioe.org NNTP Server Lines: 23 Message-ID: References: NNTP-Posting-Host: D/yWLgg4/J3ZIv1oe1tc3Q.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15; format=flowed Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 X-Antivirus-Status: Clean X-Notice: Filtered by postfilter v. 0.9.2 Content-Language: it-IT X-Antivirus: Avast (VPS 190830-2, 30/08/2019), Outbound message Xref: csiph.com it.comp.java:9318 Il 30.08.2019 12.06, dennis ha scritto: > Buongiorno a tutti, non riesco a far eseguire un comando di shell (Bash, > su Mac OS) da un programma Java. > > Ho bisogno di salvare l'output del comando ls su un file di testo. Il > file compilato del programma si trova nella stessa cartella che contiene > anche la cartella con i files il cui elenco voglio visualizzare in ls. > > questa è la parte di codice: > > String comando = "/bin/bash -c \"ls CartellePratiche > > ElencoPratiche.txt\""; In genere utilizzo il metodo exec(String[] cmdarray, String[] envp, File dir) dove cmdarray sarebbe: String[] cmdarray = {"/bin/bash", "-c", "\"ls CartellePratiche > > ElencoPratiche.txt\""}; e envp e dir possono essere null.