I'm writing a program that mimics a unix shell. It's supposed to take commands with arguments and execute them. I'm having trouble passing in the arguments into the execlp call to correctly execute the program. Here's the code I have:
Code:
// Construct the command argument array
char* args[argsEndIndex]; // Array to hold command arguments
int i = 0; // Loop counter to loop through command
int j = 0; // Loop counter for argument array
while (i <= argsEndIndex)
{
if (i != 0)
{
args[j] = cmdParts[i];
j++;
}
i++;
}
execlp("/bin/ls", "ls", args, NULL);
cmdParts is a char* array that contains the formatted command inputted. I parsed through the command above this code to insert characters so the pointers point to null terminated strings. That's also how I got argsEndIndex. For example I input this command:
Code:
ls -a -l
argsEndIndex gets correctly set to 2 because that's the index of the last argument in the command. 0 is obviously the command itself. Now when I make the execlp call I get:
Code:
ls: cannot access sH*?vH*?y: No such file or directory
Which I'm assuming it's accessing garbage data somewhere through the args array but I can't figure out why it's doing it because I'm correctly setting each element of the array.
I can post the whole code if you need it but it's long so I tried to keep this short. Any help is appreciated. Thanks!
Auto install
Hi I have a directory lets say "apps" that I then have more folders ie "email", "projectmanagment" now each of these "apps" need a mysql table, each of these
Breaking results into week blocks
I have a set of dates (and times), which are returned from a mySQL query.These usually span from 1-2 months and I need to be able to separate the results (using HTML) every sunday (monday being the
Executing an exe
Hi. I have some bizarre problem with exec (other any other method) to launch exe's. I am making a game server booking system and the part that is not working is the one with the launching the server
Production Order Enterprise Service to Manufacturing Exctn Sys (MES) ???
Hello Experts,
Accessing element of object array
HelloMy object looks like this:Array ( [0] => User Object ( [id] => [username] => [password] => [title] => [firstname] => [surname] => [email]
Forms Authentication and Refresh at Login page
Hello,
limit string by words??
hello all,I was wonder if there is a function to limit a string by the number of words instead of characters?
Printing issues with xMII 11.5
For some reason, we have one report (and only one) that is giving us fits when trying to print. The user has JRE 1.4.2_13 installed. When he clicks the print button, IE freezes, and nothing prints.
Time script, set to my time zone?
I am using this line to get the date and timeCode: $time = date(F." ".d.", ".Y." ".g.":".i.":".sa,time());How could I change this to my time zone here
I didnt code this but I need help with it
I'm sorry. i'm not a coder. I have this script for forcing download and previewing mp3. The guy that coded it made it so It took the spaces out of the filename when its downloaded. When you download a