Mercurial > hg > mep
changeset 48:f3261bd3dd49
Added the functionality of being able to run a post-run batch (windows only) or unix script read from a file specified by the run arguments.
author | Carl Bussey <c.bussey@se10.qmul.ac.uk> |
---|---|
date | Sun, 16 Jun 2013 17:06:25 +0100 |
parents | be66ee2fe9fe |
children | e4ad783e5f95 |
files | Experiment.class Experiment.java ExperimentController.class ExperimentController.java |
diffstat | 4 files changed, 49 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/Experiment.java Thu Jun 13 18:33:34 2013 +0100 +++ b/Experiment.java Sun Jun 16 17:06:25 2013 +0100 @@ -25,7 +25,7 @@ public String RESULTS_EXTENSION = ".dat"; public String SUBJECT_RESULTS_FILE = RESULTS_DIRECTORY + "subjects" + RESULTS_EXTENSION; - + public String INSTRUCTIONS_FILE = DATA_DIRECTORY + "instructions.html"; @@ -34,7 +34,8 @@ public String MIDIFILELIST_FILE = MIDI_DIRECTORY + "filelist.txt"; public String PRACTICE_MIDIFILELIST_FILE = - MIDI_DIRECTORY + "pfilelist.txt"; + MIDI_DIRECTORY + "pfilelist.txt"; + public String POST_SCRIPT; /* The GUI */ @@ -75,6 +76,9 @@ /* debugging */ private boolean debug; + + /* Post-run script */ + private boolean runPostScript; /* accessors */ public boolean getDebug() { return debug; } @@ -96,6 +100,7 @@ public int getNumUnits() { return numUnits; } public String getInstructionsFile() { return INSTRUCTIONS_FILE; } public String getSubjectID() { return subjectID; } + public boolean getRunPostScript() { return runPostScript; } public void setSubjectID(String id) { subjectID = id; results.setSubjectID(id); @@ -106,7 +111,7 @@ } /* Constructor */ - public Experiment (int sc, int cu, int nu, int sl, int md, String la, String ha, String mfd, String inf, String rdr, int fam, int lik, int quest, int fs, int de) { + public Experiment (int sc, int cu, int nu, int sl, int md, String la, String ha, String mfd, String inf, String rdr, int fam, int lik, int quest, int fs, String ps, int de) { // Setup variables debug = (de != 0); @@ -131,6 +136,12 @@ fullScreen = false; else fullScreen = true; + if (ps.equals("0")) + runPostScript = false; + else{ + runPostScript = true; + POST_SCRIPT = ps; + } if (fam == 0) askFamiliarity = false; else @@ -219,7 +230,7 @@ System.out.println("Working Directory = " + System.getProperty("user.dir")); - if (args.length == 15) { + if (args.length == 16) { // Parse Arguments int n = 0; @@ -238,6 +249,7 @@ int lik = Integer.parseInt(args[n++]); int quest = Integer.parseInt(args[n++]); int fs = Integer.parseInt(args[n++]); + String ps = args[n++]; int de = Integer.parseInt(args[n++]); if(isBooleanFormat(mdInput)){ @@ -267,7 +279,7 @@ } // Create experiment - Experiment exp = new Experiment(sc, cu, nu, sl, md, la, ha, mfd, inf, rdr, fam, lik, quest, fs, de); + Experiment exp = new Experiment(sc, cu, nu, sl, md, la, ha, mfd, inf, rdr, fam, lik, quest, fs, ps, de); // Show the GUI int width=(int)Toolkit.getDefaultToolkit().getScreenSize().getWidth(); @@ -285,7 +297,7 @@ "<default MIDI device?> " + "<scale length> <low anchor> <high anchor> " + "<midi file directory> <instructions file> <results directory> " + - " <familiarity> " + " <pleasantness> " + " <questionnaire> " + " <fullscreen> " + " <debug>"); + " <familiarity> " + " <pleasantness> " + " <questionnaire> " + " <fullscreen> " + " <post-run script> " + " <debug>"); System.exit(1); }
--- a/ExperimentController.java Thu Jun 13 18:33:34 2013 +0100 +++ b/ExperimentController.java Sun Jun 16 17:06:25 2013 +0100 @@ -9,6 +9,8 @@ import java.awt.*; import java.awt.event.*; import javax.swing.*; +import java.io.IOException; +import java.io.File; public class ExperimentController implements ActionListener, KeyListener { @@ -24,11 +26,14 @@ InterBlockPanel ibp; EndTestPanel etp; + boolean runPostScript; + /* constructor */ public ExperimentController(ExperimentGui eg) { gui = eg; exp = gui.getExperiment(); - results = exp.getSubjectResults(); + results = exp.getSubjectResults(); + runPostScript = exp.getRunPostScript(); ip = gui.getInstructionsPanel(); ibp = gui.getInterBlockPanel(); @@ -97,6 +102,31 @@ } else if (source == etp.getContinueButton()) { + if (runPostScript){ + String dir = System.getProperty("user.dir") + System.getProperty("file.separator", "/"); + String script = dir + exp.POST_SCRIPT; + String[] cmd = new String[4]; + if(script.toLowerCase().endsWith(".bat")){ + cmd[0] = "cmd.exe"; + cmd[1] = "/c"; + cmd[2] = "start"; + cmd[3] = script; + } + else{ + cmd[0] = script; + cmd[1] = " "; + cmd[2] = " "; + cmd[3] = " "; + } + Runtime runtime = Runtime.getRuntime(); + try{ + Process proc = runtime.exec(cmd); + runPostScript = false; + } catch (IOException exception){ + System.out.println("Error: Script has not excecuted."); + exception.printStackTrace(); + } + } System.exit(0); } @@ -106,7 +136,6 @@ if (sdp.allDataEntered()) { sdp.storeData(); results.writeSubjectData(); - //System.exit(0); gui.showCard("endTest"); } else reportError("You have not filled in all the information.");