Statistics
| Revision:

root / tmp / org.txm.groovy.core / src / groovy / org / txm / scripts / clix / Ls.groovy @ 479

History | View | Annotate | Download (2.8 kB)

1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
// 
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
// 
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
// 
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
// 
22
// 
23
// 
24
// $LastChangedDate: 2013-05-06 17:38:43 +0200 (lun. 06 mai 2013) $
25
// $LastChangedRevision: 2386 $
26
// $LastChangedBy: mdecorde $ 
27
//
28
package org.txm.scripts.clix;
29

    
30
import java.util.Date;
31
import java.text.DateFormat;
32
import java.io.BufferedReader;
33
import java.io.IOException;
34
import java.io.InputStream;
35
import java.io.InputStreamReader;
36
import java.util.ArrayList;
37

    
38
// List directory
39
// TODO: Auto-generated Javadoc
40

    
41
/**
42
 * The Class Ls.
43
 */
44
class Ls {
45
        
46
        /** The binpath. */
47
        String binpath = "";
48

    
49
        /**
50
         * Instantiates a new ls.
51
         *
52
         * @param binpath the binpath
53
         */
54
        public Ls(String binpath) {
55
                this.binpath = binpath;
56
        }
57

    
58
        /** The version. */
59
        String version = "0.0.0";
60
        
61
        /** The desc. */
62
        String desc = "List directory";
63

    
64
        // use a long listing format
65
        
66
        /** The isl. */
67
        private Boolean isl = false;
68

    
69
        /**
70
         * Sets the isl.
71
         */
72
        public void setIsl() {
73
                this.isl = true;
74
        }
75

    
76
        /**
77
         * Unset isl.
78
         */
79
        public void unsetIsl() {
80
                this.isl = false;
81
        }
82

    
83
        // Ls
84
        
85
        /**
86
         * Lsexe.
87
         */
88
        public void lsexe() throws IOException {
89
                ArrayList<String> args = new ArrayList<String>();
90
                args.add(binpath + "ls.exe");
91
                if (isl)
92
                        args.add("-l");
93

    
94
                ProcessBuilder pb = new ProcessBuilder(args);
95
                pb.redirectErrorStream(true);
96
                Process process = null;
97
                try {
98
                        process = pb.start();
99
                } catch (IOException e) {
100
                        System.err.println(e);
101
                }
102
                InputStream is = process.getInputStream();
103
                InputStreamReader isr = new InputStreamReader(is);
104
                BufferedReader br = new BufferedReader(isr);
105
                String line;
106
                while ((line = br.readLine()) != null) {
107
                        System.out.println(line);
108
                }
109
                int e = process.waitFor();
110
                if (e != 0) {
111
                        System.err.println("Process exited abnormally with code "
112
                                        + e
113
                                        + " at "
114
                                        + DateFormat.getDateInstance(DateFormat.LONG).format(
115
                                                        new Date()));
116
                }
117
        }
118

    
119
        /**
120
         * The main method.
121
         *
122
         * @param args the arguments
123
         */
124
        public static void main(String[] args) {
125
                Ls tt = new Ls("");
126
        }
127
}