Browse Source

Set command stream source before startup execution

git-svn-id: https://klish.googlecode.com/svn/trunk@550 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 12 years ago
parent
commit
b905be6abc
1 changed files with 13 additions and 9 deletions
  1. 13 9
      bin/clish.cpp

+ 13 - 9
bin/clish.cpp

@@ -222,14 +222,7 @@ int main(int argc, char **argv)
 	if (log)
 		clish_shell__set_log(shell, log);
 
-	/* Execute startup */
-	running = clish_shell_startup(shell);
-	if (running) {
-		fprintf(stderr, "Cannot startup clish.\n");
-		clish_shell_delete(shell);
-		return -1;
-	}
-
+	/* Set source of command stream: files or interactive tty */
 	if(optind < argc) {
 		int i;
 		/* Run the commands from the files */
@@ -237,8 +230,19 @@ int main(int argc, char **argv)
 			clish_shell_push_file(shell, argv[i], stop_on_error);
 	} else {
 		/* The interactive shell */
-		clish_shell_push_fd(shell, fdopen(dup(fileno(stdin)), "r"), stop_on_error);
+		clish_shell_push_fd(shell, fdopen(dup(fileno(stdin)), "r"),
+			stop_on_error);
 	}
+
+	/* Execute startup */
+	running = clish_shell_startup(shell);
+	if (running) {
+		fprintf(stderr, "Cannot startup clish.\n");
+		clish_shell_delete(shell);
+		return -1;
+	}
+
+	/* Main loop */
 	result = clish_shell_loop(shell);
 
 	/* Cleanup */