We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
sgegraph only submits the next processing node
### Summary
the `SGEGraph` plugin isn't submitting the entire workflow only the next required step.

### Actual behavior

When calling `workflow.run(plugin='SGEGraph', plugin_args = {'dont_resubmit_completed_jobs': True})` only the next processing node is submitted. subsequent calls are needed to iteratively processes subsequent nodes.

`workflow.run(plugin='SGE)` works as expected. submitting one job waiting until completion then submitting the next.

### Expected behavior
I would expect that `workflow.run(plugin='SGEGraph', plugin_args = {'dont_resubmit_completed_jobs': True})` would submit all processing jobs at once with later jobs being held until the earlier required jobs are finished.

### How to replicate the behavior
I'm new to nipype so I'm not sure how to get sample/example data to provide a minimal example but I think that any of the workflows in the example folder would demonstrate this issue.

### Platform details:

<!-- Please run the following code from your shell and place the output between the triple ticks, below.
python -c "import nipype; from pprint import pprint; pprint(nipype.get_info())"
-->

```
200207-13:43:08,275 nipype.utils INFO:
	 No new version available.
{'commit_hash': '792988f19',
 'commit_source': 'installation',
 'networkx_version': '2.4',
 'nibabel_version': '3.0.1',
 'nipype_version': '1.4.1',
 'numpy_version': '1.18.1',
 'pkg_path': '/mnt/isilon/meg_lab/Linux_software/anaconda3_lab/envs/nipype/lib/python3.8/site-packages/nipype',
 'scipy_version': '1.3.2',
 'sys_executable': '/mnt/isilon/meg_lab/Linux_software/anaconda3_lab/envs/nipype/bin/python',
 'sys_platform': 'linux',
 'sys_version': '3.8.1 (default, Jan  8 2020, 22:29:32) \n[GCC 7.3.0]',
 'traits_version': '5.2.0'}
```

### Execution environment

Choose one
- My python environment outside container


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `nipype/pipeline/plugins/sgegraph.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 """Parallel workflow execution via SGE
3 """
4 import os
5 import sys
6 
7 from ...interfaces.base import CommandLine
8 from .base import GraphPluginBase, logger
9 
10 
11 def node_completed_status(checknode):
12     """
13     A function to determine if a node has previously completed it's work
14     :param checknode: The node to check the run status
15     :return: boolean value True indicates that the node does not need to be run.
16     """
17     """ TODO: place this in the base.py file and refactor """
18     node_state_does_not_require_overwrite = checknode.overwrite is False or (
19         checknode.overwrite is None and not checknode._interface.always_run
20     )
21     hash_exists = False
22     try:
23         hash_exists, _, _, _ = checknode.hash_exists()
24     except Exception:
25         hash_exists = False
26     return hash_exists and node_state_does_not_require_overwrite
27 
28 
29 class SGEGraphPlugin(GraphPluginBase):
30     """Execute using SGE
31 
32     The plugin_args input to run can be used to control the SGE execution.
33     Currently supported options are:
34 
35     - template : template to use for batch job submission
36     - qsub_args : arguments to be prepended to the job execution script in the
37                   qsub call
38 
39     """
40 
41     _template = """
42 #!/bin/bash
43 #$ -V
44 #$ -S /bin/bash
45 """
46 
47     def __init__(self, **kwargs):
48         self._qsub_args = ""
49         self._dont_resubmit_completed_jobs = False
50         if "plugin_args" in kwargs and kwargs["plugin_args"]:
51             plugin_args = kwargs["plugin_args"]
52             if "template" in plugin_args:
53                 self._template = plugin_args["template"]
54                 if os.path.isfile(self._template):
55                     self._template = open(self._template).read()
56             if "qsub_args" in plugin_args:
57                 self._qsub_args = plugin_args["qsub_args"]
58             if "dont_resubmit_completed_jobs" in plugin_args:
59                 self._dont_resubmit_completed_jobs = plugin_args[
60                     "dont_resubmit_completed_jobs"
61                 ]
62         super(SGEGraphPlugin, self).__init__(**kwargs)
63 
64     def _submit_graph(self, pyfiles, dependencies, nodes):
65         def make_job_name(jobnumber, nodeslist):
66             """
67             - jobnumber: The index number of the job to create
68             - nodeslist: The name of the node being processed
69             - return: A string representing this job to be displayed by SGE
70             """
71             job_name = "j{0}_{1}".format(jobnumber, nodeslist[jobnumber]._id)
72             # Condition job_name to be a valid bash identifier (i.e. - is invalid)
73             job_name = job_name.replace("-", "_").replace(".", "_").replace(":", "_")
74             return job_name
75 
76         batch_dir, _ = os.path.split(pyfiles[0])
77         submitjobsfile = os.path.join(batch_dir, "submit_jobs.sh")
78 
79         cache_doneness_per_node = dict()
80         if (
81             self._dont_resubmit_completed_jobs
82         ):  # A future parameter for controlling this behavior could be added here
83             for idx, pyscript in enumerate(pyfiles):
84                 node = nodes[idx]
85                 node_status_done = node_completed_status(node)
86 
87                 # if the node itself claims done, then check to ensure all
88                 # dependancies are also done
89                 if node_status_done and idx in dependencies:
90                     for child_idx in dependencies[idx]:
91                         if child_idx in cache_doneness_per_node:
92                             child_status_done = cache_doneness_per_node[child_idx]
93                         else:
94                             child_status_done = node_completed_status(nodes[child_idx])
95                         node_status_done = node_status_done and child_status_done
96 
97                 cache_doneness_per_node[idx] = node_status_done
98 
99         with open(submitjobsfile, "wt") as fp:
100             fp.writelines("#!/usr/bin/env bash\n")
101             fp.writelines("# Condense format attempted\n")
102             for idx, pyscript in enumerate(pyfiles):
103                 node = nodes[idx]
104                 if cache_doneness_per_node.get(idx, False):
105                     continue
106                 else:
107                     template, qsub_args = self._get_args(
108                         node, ["template", "qsub_args"]
109                     )
110 
111                     batch_dir, name = os.path.split(pyscript)
112                     name = ".".join(name.split(".")[:-1])
113                     batchscript = "\n".join(
114                         (template, "%s %s" % (sys.executable, pyscript))
115                     )
116                     batchscriptfile = os.path.join(
117                         batch_dir, "batchscript_%s.sh" % name
118                     )
119 
120                     batchscriptoutfile = batchscriptfile + ".o"
121                     batchscripterrfile = batchscriptfile + ".e"
122 
123                     with open(batchscriptfile, "wt") as batchfp:
124                         batchfp.writelines(batchscript)
125                         batchfp.close()
126                     deps = ""
127                     if idx in dependencies:
128                         values = " "
129                         for jobid in dependencies[idx]:
130                             # Avoid dependancies of done jobs
131                             if (
132                                 not self._dont_resubmit_completed_jobs
133                                 or not cache_doneness_per_node[jobid]
134                             ):
135                                 values += "${{{0}}},".format(
136                                     make_job_name(jobid, nodes)
137                                 )
138                         if (
139                             values != " "
140                         ):  # i.e. if some jobs were added to dependency list
141                             values = values.rstrip(",")
142                             deps = "-hold_jid%s" % values
143                     jobname = make_job_name(idx, nodes)
144                     # Do not use default output locations if they are set in self._qsub_args
145                     stderrFile = ""
146                     if self._qsub_args.count("-e ") == 0:
147                         stderrFile = "-e {errFile}".format(errFile=batchscripterrfile)
148                     stdoutFile = ""
149                     if self._qsub_args.count("-o ") == 0:
150                         stdoutFile = "-o {outFile}".format(outFile=batchscriptoutfile)
151                     full_line = "{jobNm}=$(qsub {outFileOption} {errFileOption} {extraQSubArgs} {dependantIndex} -N {jobNm} {batchscript} | awk '{{print $3}}')\n".format(
152                         jobNm=jobname,
153                         outFileOption=stdoutFile,
154                         errFileOption=stderrFile,
155                         extraQSubArgs=qsub_args,
156                         dependantIndex=deps,
157                         batchscript=batchscriptfile,
158                     )
159                     fp.writelines(full_line)
160         cmd = CommandLine(
161             "bash",
162             environ=dict(os.environ),
163             resource_monitor=False,
164             terminal_output="allatonce",
165         )
166         cmd.inputs.args = "%s" % submitjobsfile
167         cmd.run()
168         logger.info("submitted all jobs to queue")
169
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/nipype/pipeline/plugins/sgegraph.py b/nipype/pipeline/plugins/sgegraph.py
--- a/nipype/pipeline/plugins/sgegraph.py
+++ b/nipype/pipeline/plugins/sgegraph.py
@@ -148,7 +148,7 @@
                     stdoutFile = ""
                     if self._qsub_args.count("-o ") == 0:
                         stdoutFile = "-o {outFile}".format(outFile=batchscriptoutfile)
-                    full_line = "{jobNm}=$(qsub {outFileOption} {errFileOption} {extraQSubArgs} {dependantIndex} -N {jobNm} {batchscript} | awk '{{print $3}}')\n".format(
+                    full_line = "{jobNm}=$(qsub {outFileOption} {errFileOption} {extraQSubArgs} {dependantIndex} -N {jobNm} {batchscript} | awk '/^Your job/{{print $3}}')\n".format(
                         jobNm=jobname,
                         outFileOption=stdoutFile,
                         errFileOption=stderrFile,

{"golden_diff": "diff --git a/nipype/pipeline/plugins/sgegraph.py b/nipype/pipeline/plugins/sgegraph.py\n--- a/nipype/pipeline/plugins/sgegraph.py\n+++ b/nipype/pipeline/plugins/sgegraph.py\n@@ -148,7 +148,7 @@\n                     stdoutFile = \"\"\n                     if self._qsub_args.count(\"-o \") == 0:\n                         stdoutFile = \"-o {outFile}\".format(outFile=batchscriptoutfile)\n-                    full_line = \"{jobNm}=$(qsub {outFileOption} {errFileOption} {extraQSubArgs} {dependantIndex} -N {jobNm} {batchscript} | awk '{{print $3}}')\\n\".format(\n+                    full_line = \"{jobNm}=$(qsub {outFileOption} {errFileOption} {extraQSubArgs} {dependantIndex} -N {jobNm} {batchscript} | awk '/^Your job/{{print $3}}')\\n\".format(\n                         jobNm=jobname,\n                         outFileOption=stdoutFile,\n                         errFileOption=stderrFile,\n", "issue": "sgegraph only submits the next processing node\n### Summary\r\nthe `SGEGraph` plugin isn't submitting the entire workflow only the next required step.\r\n\r\n### Actual behavior\r\n\r\nWhen calling `workflow.run(plugin='SGEGraph', plugin_args = {'dont_resubmit_completed_jobs': True})` only the next processing node is submitted. subsequent calls are needed to iteratively processes subsequent nodes.\r\n\r\n`workflow.run(plugin='SGE)` works as expected. submitting one job waiting until completion then submitting the next.\r\n\r\n### Expected behavior\r\nI would expect that `workflow.run(plugin='SGEGraph', plugin_args = {'dont_resubmit_completed_jobs': True})` would submit all processing jobs at once with later jobs being held until the earlier required jobs are finished.\r\n\r\n### How to replicate the behavior\r\nI'm new to nipype so I'm not sure how to get sample/example data to provide a minimal example but I think that any of the workflows in the example folder would demonstrate this issue.\r\n\r\n### Platform details:\r\n\r\n<!-- Please run the following code from your shell and place the output between the triple ticks, below.\r\npython -c \"import nipype; from pprint import pprint; pprint(nipype.get_info())\"\r\n-->\r\n\r\n```\r\n200207-13:43:08,275 nipype.utils INFO:\r\n\t No new version available.\r\n{'commit_hash': '792988f19',\r\n 'commit_source': 'installation',\r\n 'networkx_version': '2.4',\r\n 'nibabel_version': '3.0.1',\r\n 'nipype_version': '1.4.1',\r\n 'numpy_version': '1.18.1',\r\n 'pkg_path': '/mnt/isilon/meg_lab/Linux_software/anaconda3_lab/envs/nipype/lib/python3.8/site-packages/nipype',\r\n 'scipy_version': '1.3.2',\r\n 'sys_executable': '/mnt/isilon/meg_lab/Linux_software/anaconda3_lab/envs/nipype/bin/python',\r\n 'sys_platform': 'linux',\r\n 'sys_version': '3.8.1 (default, Jan  8 2020, 22:29:32) \\n[GCC 7.3.0]',\r\n 'traits_version': '5.2.0'}\r\n```\r\n\r\n### Execution environment\r\n\r\nChoose one\r\n- My python environment outside container\r\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\"\"\"Parallel workflow execution via SGE\n\"\"\"\nimport os\nimport sys\n\nfrom ...interfaces.base import CommandLine\nfrom .base import GraphPluginBase, logger\n\n\ndef node_completed_status(checknode):\n    \"\"\"\n    A function to determine if a node has previously completed it's work\n    :param checknode: The node to check the run status\n    :return: boolean value True indicates that the node does not need to be run.\n    \"\"\"\n    \"\"\" TODO: place this in the base.py file and refactor \"\"\"\n    node_state_does_not_require_overwrite = checknode.overwrite is False or (\n        checknode.overwrite is None and not checknode._interface.always_run\n    )\n    hash_exists = False\n    try:\n        hash_exists, _, _, _ = checknode.hash_exists()\n    except Exception:\n        hash_exists = False\n    return hash_exists and node_state_does_not_require_overwrite\n\n\nclass SGEGraphPlugin(GraphPluginBase):\n    \"\"\"Execute using SGE\n\n    The plugin_args input to run can be used to control the SGE execution.\n    Currently supported options are:\n\n    - template : template to use for batch job submission\n    - qsub_args : arguments to be prepended to the job execution script in the\n                  qsub call\n\n    \"\"\"\n\n    _template = \"\"\"\n#!/bin/bash\n#$ -V\n#$ -S /bin/bash\n\"\"\"\n\n    def __init__(self, **kwargs):\n        self._qsub_args = \"\"\n        self._dont_resubmit_completed_jobs = False\n        if \"plugin_args\" in kwargs and kwargs[\"plugin_args\"]:\n            plugin_args = kwargs[\"plugin_args\"]\n            if \"template\" in plugin_args:\n                self._template = plugin_args[\"template\"]\n                if os.path.isfile(self._template):\n                    self._template = open(self._template).read()\n            if \"qsub_args\" in plugin_args:\n                self._qsub_args = plugin_args[\"qsub_args\"]\n            if \"dont_resubmit_completed_jobs\" in plugin_args:\n                self._dont_resubmit_completed_jobs = plugin_args[\n                    \"dont_resubmit_completed_jobs\"\n                ]\n        super(SGEGraphPlugin, self).__init__(**kwargs)\n\n    def _submit_graph(self, pyfiles, dependencies, nodes):\n        def make_job_name(jobnumber, nodeslist):\n            \"\"\"\n            - jobnumber: The index number of the job to create\n            - nodeslist: The name of the node being processed\n            - return: A string representing this job to be displayed by SGE\n            \"\"\"\n            job_name = \"j{0}_{1}\".format(jobnumber, nodeslist[jobnumber]._id)\n            # Condition job_name to be a valid bash identifier (i.e. - is invalid)\n            job_name = job_name.replace(\"-\", \"_\").replace(\".\", \"_\").replace(\":\", \"_\")\n            return job_name\n\n        batch_dir, _ = os.path.split(pyfiles[0])\n        submitjobsfile = os.path.join(batch_dir, \"submit_jobs.sh\")\n\n        cache_doneness_per_node = dict()\n        if (\n            self._dont_resubmit_completed_jobs\n        ):  # A future parameter for controlling this behavior could be added here\n            for idx, pyscript in enumerate(pyfiles):\n                node = nodes[idx]\n                node_status_done = node_completed_status(node)\n\n                # if the node itself claims done, then check to ensure all\n                # dependancies are also done\n                if node_status_done and idx in dependencies:\n                    for child_idx in dependencies[idx]:\n                        if child_idx in cache_doneness_per_node:\n                            child_status_done = cache_doneness_per_node[child_idx]\n                        else:\n                            child_status_done = node_completed_status(nodes[child_idx])\n                        node_status_done = node_status_done and child_status_done\n\n                cache_doneness_per_node[idx] = node_status_done\n\n        with open(submitjobsfile, \"wt\") as fp:\n            fp.writelines(\"#!/usr/bin/env bash\\n\")\n            fp.writelines(\"# Condense format attempted\\n\")\n            for idx, pyscript in enumerate(pyfiles):\n                node = nodes[idx]\n                if cache_doneness_per_node.get(idx, False):\n                    continue\n                else:\n                    template, qsub_args = self._get_args(\n                        node, [\"template\", \"qsub_args\"]\n                    )\n\n                    batch_dir, name = os.path.split(pyscript)\n                    name = \".\".join(name.split(\".\")[:-1])\n                    batchscript = \"\\n\".join(\n                        (template, \"%s %s\" % (sys.executable, pyscript))\n                    )\n                    batchscriptfile = os.path.join(\n                        batch_dir, \"batchscript_%s.sh\" % name\n                    )\n\n                    batchscriptoutfile = batchscriptfile + \".o\"\n                    batchscripterrfile = batchscriptfile + \".e\"\n\n                    with open(batchscriptfile, \"wt\") as batchfp:\n                        batchfp.writelines(batchscript)\n                        batchfp.close()\n                    deps = \"\"\n                    if idx in dependencies:\n                        values = \" \"\n                        for jobid in dependencies[idx]:\n                            # Avoid dependancies of done jobs\n                            if (\n                                not self._dont_resubmit_completed_jobs\n                                or not cache_doneness_per_node[jobid]\n                            ):\n                                values += \"${{{0}}},\".format(\n                                    make_job_name(jobid, nodes)\n                                )\n                        if (\n                            values != \" \"\n                        ):  # i.e. if some jobs were added to dependency list\n                            values = values.rstrip(\",\")\n                            deps = \"-hold_jid%s\" % values\n                    jobname = make_job_name(idx, nodes)\n                    # Do not use default output locations if they are set in self._qsub_args\n                    stderrFile = \"\"\n                    if self._qsub_args.count(\"-e \") == 0:\n                        stderrFile = \"-e {errFile}\".format(errFile=batchscripterrfile)\n                    stdoutFile = \"\"\n                    if self._qsub_args.count(\"-o \") == 0:\n                        stdoutFile = \"-o {outFile}\".format(outFile=batchscriptoutfile)\n                    full_line = \"{jobNm}=$(qsub {outFileOption} {errFileOption} {extraQSubArgs} {dependantIndex} -N {jobNm} {batchscript} | awk '{{print $3}}')\\n\".format(\n                        jobNm=jobname,\n                        outFileOption=stdoutFile,\n                        errFileOption=stderrFile,\n                        extraQSubArgs=qsub_args,\n                        dependantIndex=deps,\n                        batchscript=batchscriptfile,\n                    )\n                    fp.writelines(full_line)\n        cmd = CommandLine(\n            \"bash\",\n            environ=dict(os.environ),\n            resource_monitor=False,\n            terminal_output=\"allatonce\",\n        )\n        cmd.inputs.args = \"%s\" % submitjobsfile\n        cmd.run()\n        logger.info(\"submitted all jobs to queue\")\n", "path": "nipype/pipeline/plugins/sgegraph.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\"\"\"Parallel workflow execution via SGE\n\"\"\"\nimport os\nimport sys\n\nfrom ...interfaces.base import CommandLine\nfrom .base import GraphPluginBase, logger\n\n\ndef node_completed_status(checknode):\n    \"\"\"\n    A function to determine if a node has previously completed it's work\n    :param checknode: The node to check the run status\n    :return: boolean value True indicates that the node does not need to be run.\n    \"\"\"\n    \"\"\" TODO: place this in the base.py file and refactor \"\"\"\n    node_state_does_not_require_overwrite = checknode.overwrite is False or (\n        checknode.overwrite is None and not checknode._interface.always_run\n    )\n    hash_exists = False\n    try:\n        hash_exists, _, _, _ = checknode.hash_exists()\n    except Exception:\n        hash_exists = False\n    return hash_exists and node_state_does_not_require_overwrite\n\n\nclass SGEGraphPlugin(GraphPluginBase):\n    \"\"\"Execute using SGE\n\n    The plugin_args input to run can be used to control the SGE execution.\n    Currently supported options are:\n\n    - template : template to use for batch job submission\n    - qsub_args : arguments to be prepended to the job execution script in the\n                  qsub call\n\n    \"\"\"\n\n    _template = \"\"\"\n#!/bin/bash\n#$ -V\n#$ -S /bin/bash\n\"\"\"\n\n    def __init__(self, **kwargs):\n        self._qsub_args = \"\"\n        self._dont_resubmit_completed_jobs = False\n        if \"plugin_args\" in kwargs and kwargs[\"plugin_args\"]:\n            plugin_args = kwargs[\"plugin_args\"]\n            if \"template\" in plugin_args:\n                self._template = plugin_args[\"template\"]\n                if os.path.isfile(self._template):\n                    self._template = open(self._template).read()\n            if \"qsub_args\" in plugin_args:\n                self._qsub_args = plugin_args[\"qsub_args\"]\n            if \"dont_resubmit_completed_jobs\" in plugin_args:\n                self._dont_resubmit_completed_jobs = plugin_args[\n                    \"dont_resubmit_completed_jobs\"\n                ]\n        super(SGEGraphPlugin, self).__init__(**kwargs)\n\n    def _submit_graph(self, pyfiles, dependencies, nodes):\n        def make_job_name(jobnumber, nodeslist):\n            \"\"\"\n            - jobnumber: The index number of the job to create\n            - nodeslist: The name of the node being processed\n            - return: A string representing this job to be displayed by SGE\n            \"\"\"\n            job_name = \"j{0}_{1}\".format(jobnumber, nodeslist[jobnumber]._id)\n            # Condition job_name to be a valid bash identifier (i.e. - is invalid)\n            job_name = job_name.replace(\"-\", \"_\").replace(\".\", \"_\").replace(\":\", \"_\")\n            return job_name\n\n        batch_dir, _ = os.path.split(pyfiles[0])\n        submitjobsfile = os.path.join(batch_dir, \"submit_jobs.sh\")\n\n        cache_doneness_per_node = dict()\n        if (\n            self._dont_resubmit_completed_jobs\n        ):  # A future parameter for controlling this behavior could be added here\n            for idx, pyscript in enumerate(pyfiles):\n                node = nodes[idx]\n                node_status_done = node_completed_status(node)\n\n                # if the node itself claims done, then check to ensure all\n                # dependancies are also done\n                if node_status_done and idx in dependencies:\n                    for child_idx in dependencies[idx]:\n                        if child_idx in cache_doneness_per_node:\n                            child_status_done = cache_doneness_per_node[child_idx]\n                        else:\n                            child_status_done = node_completed_status(nodes[child_idx])\n                        node_status_done = node_status_done and child_status_done\n\n                cache_doneness_per_node[idx] = node_status_done\n\n        with open(submitjobsfile, \"wt\") as fp:\n            fp.writelines(\"#!/usr/bin/env bash\\n\")\n            fp.writelines(\"# Condense format attempted\\n\")\n            for idx, pyscript in enumerate(pyfiles):\n                node = nodes[idx]\n                if cache_doneness_per_node.get(idx, False):\n                    continue\n                else:\n                    template, qsub_args = self._get_args(\n                        node, [\"template\", \"qsub_args\"]\n                    )\n\n                    batch_dir, name = os.path.split(pyscript)\n                    name = \".\".join(name.split(\".\")[:-1])\n                    batchscript = \"\\n\".join(\n                        (template, \"%s %s\" % (sys.executable, pyscript))\n                    )\n                    batchscriptfile = os.path.join(\n                        batch_dir, \"batchscript_%s.sh\" % name\n                    )\n\n                    batchscriptoutfile = batchscriptfile + \".o\"\n                    batchscripterrfile = batchscriptfile + \".e\"\n\n                    with open(batchscriptfile, \"wt\") as batchfp:\n                        batchfp.writelines(batchscript)\n                        batchfp.close()\n                    deps = \"\"\n                    if idx in dependencies:\n                        values = \" \"\n                        for jobid in dependencies[idx]:\n                            # Avoid dependancies of done jobs\n                            if (\n                                not self._dont_resubmit_completed_jobs\n                                or not cache_doneness_per_node[jobid]\n                            ):\n                                values += \"${{{0}}},\".format(\n                                    make_job_name(jobid, nodes)\n                                )\n                        if (\n                            values != \" \"\n                        ):  # i.e. if some jobs were added to dependency list\n                            values = values.rstrip(\",\")\n                            deps = \"-hold_jid%s\" % values\n                    jobname = make_job_name(idx, nodes)\n                    # Do not use default output locations if they are set in self._qsub_args\n                    stderrFile = \"\"\n                    if self._qsub_args.count(\"-e \") == 0:\n                        stderrFile = \"-e {errFile}\".format(errFile=batchscripterrfile)\n                    stdoutFile = \"\"\n                    if self._qsub_args.count(\"-o \") == 0:\n                        stdoutFile = \"-o {outFile}\".format(outFile=batchscriptoutfile)\n                    full_line = \"{jobNm}=$(qsub {outFileOption} {errFileOption} {extraQSubArgs} {dependantIndex} -N {jobNm} {batchscript} | awk '/^Your job/{{print $3}}')\\n\".format(\n                        jobNm=jobname,\n                        outFileOption=stdoutFile,\n                        errFileOption=stderrFile,\n                        extraQSubArgs=qsub_args,\n                        dependantIndex=deps,\n                        batchscript=batchscriptfile,\n                    )\n                    fp.writelines(full_line)\n        cmd = CommandLine(\n            \"bash\",\n            environ=dict(os.environ),\n            resource_monitor=False,\n            terminal_output=\"allatonce\",\n        )\n        cmd.inputs.args = \"%s\" % submitjobsfile\n        cmd.run()\n        logger.info(\"submitted all jobs to queue\")\n", "path": "nipype/pipeline/plugins/sgegraph.py"}]}