User not logged in - login - register
Home Calendar Books School Tool Photo Gallery Message Boards Users Statistics Advertise Site Info
go to bottom | |
 Message Boards » » C++/Unix Help Page [1]  
jaZon
All American
27048 Posts
user info
edit post

Why oh WHY doesn't this work?

execlp("FUCKYOU", (char *)huh[i], (char *)huh[++i])

and just for shits, huh is some random ass array of integers.

command line FUCKYOU 1 2, for example, works fine.

nubwork

[Edited on February 7, 2008 at 10:10 PM. Reason : ]

2/7/2008 10:09:33 PM

Aficionado
Suspended
22518 Posts
user info
edit post

I FEEL YOUR *NIX PAIN

2/7/2008 10:13:39 PM

llama
All American
841 Posts
user info
edit post

what's not working? compilation error?

2/7/2008 10:31:12 PM

jaZon
All American
27048 Posts
user info
edit post

Compiles fine. Just seems to skip over it altogether.

I could just have FUCKYOU set to print out "fuck you," but nothing happens.

Unless I'm just a compelte tard and nothing's supposed to happen

[Edited on February 7, 2008 at 10:36 PM. Reason : ]

2/7/2008 10:36:42 PM

dakota_man
All American
26584 Posts
user info
edit post

is FUCKYOU in the path or are you providing the entire path?

[Edited on February 7, 2008 at 10:39 PM. Reason : also don't be lazy and see what it returns]

2/7/2008 10:38:44 PM

jaZon
All American
27048 Posts
user info
edit post

same path

[Edited on February 7, 2008 at 10:39 PM. Reason : ]

2/7/2008 10:39:09 PM

jaZon
All American
27048 Posts
user info
edit post

don't know what i did, but finally got it to return a vlue....of course it indicates an error. checking errno just says unknown error

i'm assuming whatever the hell FUCKYOU is taking for parameters doesn't like the way it's being casted. hurray.....now wtf do i do

[Edited on February 7, 2008 at 10:50 PM. Reason : ]

2/7/2008 10:44:00 PM

llama
All American
841 Posts
user info
edit post

does FUCKYOU take 2 char pointers?

2/8/2008 8:24:49 AM

jaZon
All American
27048 Posts
user info
edit post

well let's just say it doesn't - it's supposed to, mind you.

i decided to write my own FUCKYOU just to see if I could get the execlp to work

so now FUCKYOU is :

int main(int argc, char* argv[])
{
cout << "argv[0]" << argv[0] << endl;
cout << "argv[1]" << (int)argv[1] << endl;
cout << "argv[2]" << (int)argv[2] << endl;

return 0;
}



So I changed the other a bit:
char args[] = { numbers[numIndex], numbers[++numIndex] };
execlp( "FUCKYOU", args );


Now that actually works.....to an extent. It will run FUCKYOU, but it certainly doesn't output what it's supposed to.

[Edited on February 8, 2008 at 5:51 PM. Reason : ]

2/8/2008 5:50:19 PM

Scary Larry
Suspended
644 Posts
user info
edit post

     The arguments represented by arg0... are pointers  to  null-
terminated character strings. These strings constitute the
argument list available to the new process image. The list
is terminated by a null pointer. The arg0 argument should
point to a filename that is associated with the process
being started by one of the exec functions.


You're violating two preconditions of the function, very well into "undefined behavior" territory.

2/9/2008 8:33:42 AM

dakota_man
All American
26584 Posts
user info
edit post

yeah, I didn't even notice this:

Quote :
"and just for shits, huh is some random ass array of integers."

2/9/2008 12:56:52 PM

jaZon
All American
27048 Posts
user info
edit post

2/9/2008 3:23:33 PM

minion
Veteran
374 Posts
user info
edit post

so i dont really know what you're trying to do at all, but if you're trying to get integers from the command line, if you're positive they're going to be ints, do an atoi(argv[1]) and it'll return a proper int.

2/9/2008 6:09:53 PM

minion
Veteran
374 Posts
user info
edit post

and actually it looks like you're misinterpreting how to use execlp ... you need to properly setup your args - argv[0] should always be the name of the executable. this is assuming FUCKYOU is in your current path, as well.

int retVal;
retVal = execlp ("FUCKYOU", "FUCKYOU", argv[1], argv[2], (char *)0);

i have a feeling that'll do exactly what you're trying to do.

2/9/2008 6:15:48 PM

Scary Larry
Suspended
644 Posts
user info
edit post

That's one of the preconditions he violates, but to say resolving that would result in it working would still be assuming execlp never copies it as a null-terminated string before the next process gets the pointer. If it does, and say you're passing (int) 0xff0000ff, you're gonna get ff00 from the copy and then derefencing will append whatever crud happens to follow it in its new location. I imagine that would be implementation-specific behavior.

[Edited on February 9, 2008 at 6:31 PM. Reason : .]

2/9/2008 6:29:33 PM

jaZon
All American
27048 Posts
user info
edit post

^^ & ^ both dead on.

Thanks for the help guys.

I'm still getting fucked by ^ that, though.

If I pass argv[1] and argv[2] directly into excelp it works fine (whether it's supposed to or not is another story). God forbid I try to pass anything else, though

2/10/2008 4:15:09 PM

jaZon
All American
27048 Posts
user info
edit post

nm, i figured out my stupid mistake

thanks again everyone!

no way in hell I could have done it without help

2/10/2008 5:01:51 PM

skokiaan
All American
26447 Posts
user info
edit post

you can't get off that easy. what was the mistake

2/10/2008 5:07:49 PM

dakota_man
All American
26584 Posts
user info
edit post

he wasn't calling it correctly

looks like it's supposed to be:

int rc = execlp("executable name", "executable name", some null terminated char *s, NULL);

and he was casting ints to pass in instead of passing character strings.

2/10/2008 8:40:29 PM

jaZon
All American
27048 Posts
user info
edit post

^ basically got it.

Big retard moment on my part

I just used sprintf to drop the ints into a null terminated char array and it worked perfectly

[Edited on February 19, 2008 at 10:33 AM. Reason : ]

2/19/2008 10:26:41 AM

 Message Boards » Tech Talk » C++/Unix Help Page [1]  
go to top | |
Admin Options : move topic | lock topic

© 2024 by The Wolf Web - All Rights Reserved.
The material located at this site is not endorsed, sponsored or provided by or on behalf of North Carolina State University.
Powered by CrazyWeb v2.38 - our disclaimer.