diff --git a/contribs/torque/qsub.pl b/contribs/torque/qsub.pl
index 758b443aa38388c63be14f44263f06d61995c265..913c9a1a13d8475cdcd74ccb424fc8e4447c75db 100755
--- a/contribs/torque/qsub.pl
+++ b/contribs/torque/qsub.pl
@@ -215,9 +215,15 @@ if($interactive) {
 
 	$command = "$sbatch";
 
-	$command .= " -D $directive_prefix" if $directive_prefix;
+	if ($directive_prefix) {
+		$command .= " -D $directive_prefix";
+		$ENV{SBATCH_WORK_DIR} = $directive_prefix;
+	}
 	$command .= " -e $err_path" if $err_path;
-	$command .= " -o $out_path" if $out_path;
+	if ($out_path) {
+		$command .= " -o $out_path";
+		$ENV{SBATCH_STDOUT} = $out_path;
+	}
 
 #	The job size specification may be within the batch script,
 #	Reset task count if node count also specified
diff --git a/src/plugins/job_submit/pbs/spank_pbs.c b/src/plugins/job_submit/pbs/spank_pbs.c
index 285f8bc13f1c4202c03e9efac720bf04991de6c3..080d9accfa61c1e5501727812754d3ccc2dc0ed3 100644
--- a/src/plugins/job_submit/pbs/spank_pbs.c
+++ b/src/plugins/job_submit/pbs/spank_pbs.c
@@ -38,11 +38,55 @@
 \*****************************************************************************/
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 #include "slurm/spank.h"
 
 SPANK_PLUGIN(pbs, 1);
 
+/* Set a few environment variables for use by the Epilog script
+ * SPANK_NCCS_STDOUT_FILE  will be set to the job's NCCS_STDOUT_FILE env
+ * SPANK_SLURM_STDOUT_FILE will be set to the job's stdout file
+ *
+ * NOTE: the ac and av represent the argc and argv arguments to the SPANK
+ * plugin, not those of the user command
+ */
+int slurm_spank_init_post_opt(spank_t sp, int ac, char **av)
+{
+	char *nccs_stdout, *sbatch_stdout, *sbatch_dir;
+	char *cwd = NULL;
+	int i = 4096;
+
+	if ((nccs_stdout = getenv("NCCS_STDOUT_FILE")))
+		spank_job_control_setenv(sp, "NCCS_STDOUT_FILE", nccs_stdout,1);
+
+	sbatch_stdout = getenv("SBATCH_STDOUT");
+	if (!sbatch_stdout)
+		sbatch_stdout = "slurm-%J.out";
+	sbatch_dir = getenv("SBATCH_WORK_DIR");
+	while (!sbatch_dir) {
+		cwd = realloc(cwd, i);
+		sbatch_dir = getcwd(cwd, i);
+		i *= 16;
+	}
+	if (sbatch_stdout[0] == '/') {
+		spank_job_control_setenv(sp, "SLURM_STDOUT_FILE",
+					 sbatch_stdout, 1);
+	} else {
+		i = strlen(sbatch_dir) + strlen(sbatch_stdout) + 2;
+		char *tmp = malloc(i);
+		snprintf(tmp, i, "%s/%s", sbatch_dir, sbatch_stdout);
+		spank_job_control_setenv(sp, "SLURM_STDOUT_FILE", tmp, 1);
+		free(tmp);
+	}
+	if (cwd)
+		free(cwd);
+
+	return ESPANK_SUCCESS;
+}
+
+/* Configure a bunch of PBS_* environment variables based upon the SLURM_*
+ * environment variables that are set by Slurm. */
 int slurm_spank_task_init(spank_t sp, int ac, char **av)
 {
 	char val[30000];
@@ -119,5 +163,5 @@ int slurm_spank_task_init(spank_t sp, int ac, char **av)
 		spank_setenv(sp, "PBS_TASKNUM", val, 1);
 	}
 
-	return 0;
+	return ESPANK_SUCCESS;
 }