Skip to content
This repository has been archived by the owner on Nov 9, 2023. It is now read-only.

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpolitz committed Feb 27, 2023
1 parent 56363da commit ebca740
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
21 changes: 17 additions & 4 deletions GradeServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ static String streamToString(InputStream out) throws IOException {
int c = out.read();
if(c == -1) { break; }
result += (char)c;
System.out.println(System.currentTimeMillis() + "; just read: " + (char)c);
}
return result;
}
Expand All @@ -37,8 +36,8 @@ static String exec(String[] cmd) throws IOException {
.command(Arrays.asList(cmd))
.redirectErrorStream(true)
.start();
InputStream out = p.getInputStream();
return String.format("%s\n", streamToString(out));
InputStream outputOfBash = p.getInputStream();
return String.format("%s\n", streamToString(outputOfBash));
}

}
Expand All @@ -48,7 +47,9 @@ public String handleRequest(URI url) throws IOException {
if (url.getPath().equals("/grade")) {
String[] parameters = url.getQuery().split("=");
if (parameters[0].equals("repo")) {
return ExecHelpers.exec(new String[]{"bash", "grade.sh", parameters[1]});
String[] cmd = {"bash", "grade.sh", parameters[1]};
String result = ExecHelpers.exec(cmd);
return result;
}
else {
return "Couldn't find query parameter repo";
Expand All @@ -73,3 +74,15 @@ public static void main(String[] args) throws IOException {
}
}

class ExecExamples {
public static void main(String[] args) throws IOException {
String[] cmd1 = {"ls", "lib"};
System.out.println(ExecHelpers.exec(cmd1));

String[] cmd2 = {"pwd"};
System.out.println(ExecHelpers.exec(cmd2));

String[] cmd3 = {"touch", "a-new-file.txt"};
System.out.println(ExecHelpers.exec(cmd3));
}
}
7 changes: 6 additions & 1 deletion grade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@ CPATH='.:lib/hamcrest-core-1.3.jar:lib/junit-4.13.2.jar'

rm -rf student-submission
git clone $1 student-submission
echo 'Finished cloning'
echo 'Finished cloning'

cp student-submission/ListExamples.java ./
javac -cp $CPATH *.java
java -cp $CPATH org.junit.runner.JUnitCore TestListExamples

0 comments on commit ebca740

Please sign in to comment.