7
7
8
8
#pysearch is a tool to debug incoming errors from python scripts
9
9
cmd = input ("py-search > " )
10
- try :
11
- process = subprocess .Popen (shlex .split (cmd ), stdout = subprocess .PIPE ,
12
- stderr = subprocess .PIPE , cwd = "." )
13
10
14
- stdout , stderr = process .communicate ()
11
+ # Added input validation to restrict commands to only 'python' or 'python3'
12
+ if not (cmd .startswith ("python" ) or cmd .startswith ("python3" )):
13
+ print ("QuickOverflow Error: Only 'python' or 'python3' commands are allowed." )
14
+ print ("Use QuickOverflow’s search feature to browse directories instead." )
15
15
16
- print (stdout .decode ('utf-8' ))
17
- print (stderr .decode ('utf-8' ))
16
+ else :
17
+ try :
18
+ process = subprocess .Popen (shlex .split (cmd ), stdout = subprocess .PIPE ,
19
+ stderr = subprocess .PIPE , cwd = "." )
18
20
19
- pyoverflow3 . submit_error ( str ( stderr ), 2 )
21
+ stdout , stderr = process . communicate ( )
20
22
21
- except Exception as e :
22
- print ("QuickOverflow Error: " + e )
23
+ print (stdout .decode ('utf-8' ))
24
+ print (stderr .decode ('utf-8' ))
25
+
26
+ # Checking if there's an actual error
27
+ error_output = stderr .decode ('utf-8' )
28
+ if error_output :
29
+ # wrapping the error in a try-except block to handle any exceptions
30
+ try :
31
+ pyoverflow3 .submit_error (str (error_output ),2 )
32
+ except Exception as e :
33
+ print ("QuickOverflow Error: " + str (e ))
34
+
35
+ # Existing error handling retained and cleaned up to formate error messages properly
36
+ except Exception as e :
37
+ print ("QuickOverflow Error: " + str (e ))
0 commit comments