-
Notifications
You must be signed in to change notification settings - Fork 2
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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') | ||
if thrid_argument_is_input: | ||
USER_INPUT = sys.argv[3] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is this input sent from? |
||
|
||
|
||
if LANG == 'c': | ||
|
@@ -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 | ||
|
||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!!