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!
How to submit a form to the same page?
I have a table containing information about books in my library and this table has the following columns: id, title, category. What I want to do is to make a form that will allow me to sort these
Deleted Delivery but material wont return
We deleted a delivery but the material its still pending.
Cursor statement failed with errors
Following statement failed with the errors.
Forgot password won't work
My forgot password thing is not working properly. It is giving me this errorMailbox unavailable. The server response was: <andrewsmd87@gmail.com> No such user here
writing my own sobel filter convolution - something is wrong
I am trying to keep it very simple, I cant see anything wrong with my logic, could anybody help point me to the right direction?!! Code: { int Shorizontal[] = {-1, 0, 1, -2, 0, 2, -1, 0, 1}; int
Output Full URL of Current Page
Let's say I am currently viewing a dynamic page: http://www.mydomain.com/directory/index.php?type=flowers I want this URL to be output on the page, but not including the end parameters.
temporary objects
Until now i thought every temporary object in C++ is created as constant. I'm wondering why my compiler (gcc) is reporting an error on line k.f();, but not g().f(); and g() = k;. Does anyone
problem when runing a funciton
I am trying to connect to database using a funciton in a functions.php <?phpfunction connect_db_Blog (){ $con=mysql_connect("localhost","root","");
Is it possible to put an entire 500-page book in a database with PHP?
I am working on an intranet and I was wondering if its possible to code php with mysql to enter a full-text 500 page book into a database since I will be doing lots of updates to the pages? thanks
Need help with some php code :)
Hey! I'm quite new to this whole thing, so please don't fire me with shait on this one =DI'm trying to learn PHP and MySQL, and atm I am trying to make a website which corresponds with a database - a