Commit 3e74a2e3 authored by Nicolas Wavrant's avatar Nicolas Wavrant

runner: handles better the "cd" command in minishell.

It didn't react well in "timeout X cd" because cd is a shell function
parent c2f048cc
...@@ -716,6 +716,7 @@ def runCommand(): ...@@ -716,6 +716,7 @@ def runCommand():
for cmd in parsed_commands: for cmd in parsed_commands:
if 'cd' == cmd[:2]: if 'cd' == cmd[:2]:
cmd = cmd.split(' '); cmd = cmd.split(' ');
real_cmd = cmd[:]
if len(cmd) == 1: if len(cmd) == 1:
cmd.append(os.environ.get('HOME')) cmd.append(os.environ.get('HOME'))
# shorten directory's name, to avoid things like : /a/../b # shorten directory's name, to avoid things like : /a/../b
...@@ -725,7 +726,7 @@ def runCommand(): ...@@ -725,7 +726,7 @@ def runCommand():
# save new cwd in the config file # save new cwd in the config file
open(app.config['minishell_cwd_file'], 'w').write(cwd) open(app.config['minishell_cwd_file'], 'w').write(cwd)
# if the command was just cd, execute it. Otherwise, execute the rest # if the command was just cd, execute it. Otherwise, execute the rest
command = command.replace(' '.join(cmd), '').strip(';') command = command.replace(' '.join(real_cmd), '').strip(';')
if not command: if not command:
return jsonify(path=cwd, data="Changed directory, now in : "+cwd) return jsonify(path=cwd, data="Changed directory, now in : "+cwd)
try: try:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment