Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
byit-myth-job
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liyuan
byit-myth-job
Commits
7c2dd41c
Commit
7c2dd41c
authored
Feb 03, 2020
by
guominglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
测试python调用
parent
b2a27959
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
7 deletions
+24
-7
TestPy.java
...t/byit-demo-client/src/main/java/com/byit/job/TestPy.java
+24
-7
No files found.
demo-client/byit-demo-client/src/main/java/com/byit/job/TestPy.java
View file @
7c2dd41c
...
@@ -5,29 +5,46 @@ import org.apache.commons.exec.DefaultExecutor;
...
@@ -5,29 +5,46 @@ import org.apache.commons.exec.DefaultExecutor;
import
org.apache.commons.exec.ExecuteWatchdog
;
import
org.apache.commons.exec.ExecuteWatchdog
;
import
org.apache.commons.exec.PumpStreamHandler
;
import
org.apache.commons.exec.PumpStreamHandler
;
import
java.io.
*
;
import
java.io.
ByteArrayOutputStream
;
import
java.
nio.charset.Charset
;
import
java.
io.IOException
;
import
java.nio.charset.StandardCharsets
;
import
java.nio.charset.StandardCharsets
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
TestPy
{
public
class
TestPy
{
public
static
void
main
(
String
[]
args
)
throws
IOException
,
InterruptedException
{
public
static
void
main
(
String
[]
args
)
throws
IOException
,
InterruptedException
{
List
<
ExecuteWatchdog
>
watchdogList
=
new
ArrayList
<>();
Thread
thread
=
new
Thread
(()
->
{
ByteArrayOutputStream
outputStream
=
new
ByteArrayOutputStream
();
ByteArrayOutputStream
outputStream
=
new
ByteArrayOutputStream
();
PumpStreamHandler
pumpStreamHandler
=
new
PumpStreamHandler
(
outputStream
,
outputStream
,
null
);
PumpStreamHandler
pumpStreamHandler
=
new
PumpStreamHandler
(
outputStream
,
outputStream
,
null
);
ExecuteWatchdog
watchdog
=
new
ExecuteWatchdog
(
Integer
.
MAX_VALUE
);
ExecuteWatchdog
watchdog
=
new
ExecuteWatchdog
(
Integer
.
MAX_VALUE
);
watchdogList
.
add
(
watchdog
);
DefaultExecutor
defaultExecutor
=
new
DefaultExecutor
();
DefaultExecutor
defaultExecutor
=
new
DefaultExecutor
();
defaultExecutor
.
setWatchdog
(
watchdog
);
defaultExecutor
.
setWatchdog
(
watchdog
);
defaultExecutor
.
setExitValues
(
null
);
defaultExecutor
.
setExitValues
(
null
);
defaultExecutor
.
setStreamHandler
(
pumpStreamHandler
);
defaultExecutor
.
setStreamHandler
(
pumpStreamHandler
);
CommandLine
commandline
=
new
CommandLine
(
"python"
);
CommandLine
commandline
=
new
CommandLine
(
"python"
);
commandline
.
addArgument
(
"D:\\2020project\\byit-myth-job\\demo-client\\byit-demo-client\\test.py"
);
commandline
.
addArgument
(
"D:\\workspace\\pycharmWorkSpace\\test\\com.test\\Test.py"
);
int
execute
=
defaultExecutor
.
execute
(
commandline
);
int
execute
=
0
;
try
{
execute
=
defaultExecutor
.
execute
(
commandline
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
byte
[]
bytes
=
outputStream
.
toByteArray
();
byte
[]
bytes
=
outputStream
.
toByteArray
();
Thread
.
sleep
(
3000
);
watchdog
.
destroyProcess
();
System
.
out
.
println
(
execute
);
System
.
out
.
println
(
execute
);
System
.
out
.
println
(
new
String
(
bytes
,
0
,
bytes
.
length
,
StandardCharsets
.
UTF_8
));
System
.
out
.
println
(
new
String
(
bytes
,
0
,
bytes
.
length
,
StandardCharsets
.
UTF_8
));
});
thread
.
start
();
Thread
.
sleep
(
10000
);
watchdogList
.
forEach
(
watchdog
->{
watchdog
.
destroyProcess
();
});
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment