@@ -62,7 +62,6 @@ public static void main(String[] args) {
62
62
private ArrayList <String > programArgs = null ;
63
63
private String commandString = null ;
64
64
private String inputFile = null ;
65
- private String module = null ;
66
65
private boolean ignoreEnv = false ;
67
66
private boolean inspectFlag = false ;
68
67
private boolean verboseFlag = false ;
@@ -104,9 +103,10 @@ protected List<String> preprocessArguments(List<String> arguments, Map<String, S
104
103
inspectFlag = true ;
105
104
break ;
106
105
case "-m" :
107
- i += 1 ;
108
- if (i < arguments .size ()) {
109
- module = arguments .get (i );
106
+ if (i + 1 < arguments .size ()) {
107
+ // don't increment i here so that we capture the correct args
108
+ String module = arguments .get (i + 1 );
109
+ commandString = "import runpy; runpy._run_module_as_main('" + module + "')" ;
110
110
} else {
111
111
print ("Argument expected for the -m option" );
112
112
printShortHelp ();
@@ -179,7 +179,7 @@ protected List<String> preprocessArguments(List<String> arguments, Map<String, S
179
179
}
180
180
}
181
181
182
- if (inputFile != null || commandString != null || module != null ) {
182
+ if (inputFile != null || commandString != null ) {
183
183
i += 1 ;
184
184
if (i < arguments .size ()) {
185
185
programArgs .addAll (arguments .subList (i , arguments .size ()));
@@ -252,7 +252,7 @@ protected void launch(Builder contextBuilder) {
252
252
try (Context context = contextBuilder .build ()) {
253
253
runVersionAction (versionAction , context .getEngine ());
254
254
255
- if (!quietFlag && (verboseFlag || (commandString == null && inputFile == null && module == null && stdinIsInteractive ))) {
255
+ if (!quietFlag && (verboseFlag || (commandString == null && inputFile == null && stdinIsInteractive ))) {
256
256
print ("Python " + evalInternal (context , "import sys; sys.version + ' on ' + sys.platform" ).asString ());
257
257
if (!noSite ) {
258
258
print ("Type \" help\" , \" copyright\" , \" credits\" or \" license\" for more information." );
0 commit comments