1 |
/* $Id: min_shell.c,v 1.5 2006/06/15 22:15:10 joko Exp $ */ |
2 |
|
3 |
#include <stdlib.h> |
4 |
#include <stdio.h> |
5 |
#include <errno.h> |
6 |
|
7 |
#include "min_shell.h" |
8 |
|
9 |
|
10 |
#define MAX_COMMAND_LENGTH 1024 |
11 |
|
12 |
int main(int argc, char * argv[]) { |
13 |
if (argc == 1) { |
14 |
//printf("No arguments given."); |
15 |
//exit(EXIT_FAILURE); |
16 |
char filename[255] = "abc\0"; |
17 |
BOOL background = 0; |
18 |
os_start_process(filename, background); |
19 |
} |
20 |
|
21 |
if (argc == 2) { |
22 |
FILE * script = fopen(argv[1], "r"); |
23 |
run_commands(script); |
24 |
fclose(script); |
25 |
} |
26 |
} |
27 |
|
28 |
void run_commands(FILE * fp) { |
29 |
|
30 |
char command[MAX_COMMAND_LENGTH]; |
31 |
|
32 |
fgets(command, MAX_COMMAND_LENGTH, fp); |
33 |
chomp(command); |
34 |
|
35 |
execute_command(command); |
36 |
} |
37 |
|
38 |
|
39 |
void execute_command(char * command) { |
40 |
printf("process_command: %s\n", command); |
41 |
os_start_process(command, 0); |
42 |
} |
43 |
|