Skip to content

CPP input in python tutor #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 16, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions run_cpp_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
DN = '.' # so that we always have an executable path like ./usercode.exe
USER_PROGRAM = sys.argv[1] # string containing the program to be run
LANG = sys.argv[2] # 'c' for C or 'cpp' for C++
USER_INPUT = ""

prettydump = ('--prettydump' in sys.argv)

prettydump = False
if len(sys.argv) > 3:
if sys.argv[3] == '--prettydump':
prettydump = True
thrid_argument_is_input = (sys.argv[3] != '--prettydump')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: Change to third_argument_is_input

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!!

if thrid_argument_is_input:
USER_INPUT = sys.argv[3]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I understand this well, but are you sending the entire STDIN in a command line argument? This seems inefficient and error-prone. For example, how do you make sure that the contents of the input are not interpreted as a fourth argument when you send it from the command line? IMHO a better approach is saving the input in a file, and sending the file name as a command-line argument

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Daniel, I also have this concern. However, it is the way that the author did initially with the user code and it also has spaces and special characters. Could you look a this file?https://github.com/JuezUN/OnlinePythonTutor/blob/cpp-input/v4-cokapi/cokapi.js#L243 I assumed this would be safe as the code is also sent via command line and it has a lot of spaces and special characters

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this input sent from?



if LANG == 'c':
Expand Down Expand Up @@ -66,7 +69,9 @@
'--source-filename=' + FN,
'--trace-filename=' + VGTRACE_PATH,
EXE_PATH],
stdout=PIPE, stderr=PIPE)
stdout=PIPE, stderr=PIPE, stdin=PIPE)

valgrind_p.stdin.write(USER_INPUT)
(valgrind_stdout, valgrind_stderr) = valgrind_p.communicate()
valgrind_retcode = valgrind_p.returncode

Expand Down