FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java-code-example/ExecuteLine/ShellExecute.java at master · cherkavi/java-code-example · GitHub
cherkavi
/
java-code-example
Public
Notifications
You must be signed in to change notification settings
Fork
4
Star
0
Code
Issues
0
Pull requests
42
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
java-code-example
/
ExecuteLine
/
ShellExecute.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
71 lines (60 loc) · 2.01 KB
Breadcrumbs
java-code-example
/
ExecuteLine
/
ShellExecute.java
Copy path
File metadata and controls
executable file
·
71 lines (60 loc) · 2.01 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package
com
.
cherkashin
.
vitaliy
.
application
;
import
java
.
io
.
BufferedReader
;
import
java
.
io
.
IOException
;
import
java
.
io
.
InputStream
;
import
java
.
io
.
InputStreamReader
;
public
class
ShellExecute
{
class
StreamGobbler
extends
Thread
{
InputStream
is
;
String
type
;
StreamGobbler
(
InputStream
is
,
String
type
)
{
this
.
is
=
is
;
this
.
type
=
type
;
}
public
void
run
()
{
try
{
InputStreamReader
isr
=
new
InputStreamReader
(
is
);
BufferedReader
br
=
new
BufferedReader
(
isr
);
String
line
=
null
;
while
( (
line
=
br
.
readLine
()) !=
null
)
System
.
out
.
println
(
this
.
type
+
"> "
+
line
);
}
catch
(
IOException
ioe
)
{
ioe
.
printStackTrace
();
}
}
}
/**
* @param command - Windows command
* @return
* <ul>
* <li><b>0</b> - âûïîëíåíî </li>
* <li><b>>0</b> - åñòü îøèáêè </li>
* </ul>
* */
public
static
int
execute
(
String
command
)
throws
Exception
{
// System.out.println("begin");
String
[]
cmd
=
new
String
[
3
];
cmd
[
0
] =
"cmd.exe"
;
cmd
[
1
] =
"/C"
;
cmd
[
2
] =
command
;
Runtime
rt
=
Runtime
.
getRuntime
();
// System.out.println("Execing " + cmd[0] + " " + cmd[1] + " " + cmd[2]);
Process
proc
=
rt
.
exec
(
cmd
);
// any error message?
// ShellExecute.StreamGobbler errorGobbler = new ShellExecute().new StreamGobbler(proc.getErrorStream(), "ERROR");
// any output?
// ShellExecute.StreamGobbler outputGobbler = new ShellExecute().new StreamGobbler(proc.getInputStream(), "OUTPUT");
// kick them off
// errorGobbler.start();
// outputGobbler.start();
// any error???
return
proc
.
waitFor
();
// System.out.println("ExitValue: " + exitVal);
// System.out.println("-end-");
}
}
Back
|
FazBrowse Home
|
New Git URL