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!
php problem?
I don't think I'm stupid, but maybe I am.I am working on a sit for a friend I am try to put a link on a page and it is not working in FireFox and Safari. It works in IE but nothing else.I can get it
how to get different value in second view of webdynpro?
hello guys,
a very simple php header question (sorry!)
Firstly...I do apologise if this annoys anyone....a header errorI'm do not know php & have tried removing all "white space" but I cant seem to stop the error displaying.Its a very
Procedural to OOP
John Kleijn said that to avoid writing "crappy code", we should learn OOP and common OO principles. I've started reading OOP tutorials including the design patterns. And John is right, this
Dump with added_funcion cl_salv_table
Hi there, I'm having some troubles adding a self defined function to an ALV in fullscreen. The thing is that I'm getting a dump after I press de button of my added function; the exception is
Select Lists into MYSQL
Hello All, I am new to PHP @ 1 week. So borrowing code anywhere I can. I am making progress, but hit a snag. I have 2 list boxes, that I use to move items left to right. When I click submit I want
Making multiple rows with one query
I have a table called efed_handler_characters with two fields handler_id and bio_id. What query 2 is supposed to do is get the id from the handler and then with each char(acter) is supposed to make a
Different actions for different parts of a string
<?phpfunction dosomething($string, $else = '') { if (empty($else)) $string = "<b>$string</b>"; else $string =
do while...woes
I'm sure this is childsplay but it is stumping me, everytime i try what I think would make this work, the page hangs... what am i doing wrong here??<?php$number = 5;?><?phpwhile
HTML Viewer HIDE scrollbar
How can I disable scrollbars in a HTML Viewer control? I can't hide them. Even i have enough space but i am getting this grey inactive scrollbar....