# hot to put a c++ program in the web ?



## rasslove (Apr 14, 2009)

Dear all,

I have a huge c++ program (gcc compiled) that runs on a linux console. It's an interactive program in the sense that it requires the user to enter some information through the console in order to process and give some complicated output (cout, cin). For a naive illustration, imagine a program asking you for your age on the console, you enter it and the program gives you your year of birth. The same, but a bit more complicated is my program.

My problem is just that I need it to be executed in a browser by people on the other side of the world. I do have a server where it can run, but I don't know how to make the necessary interface. Could someone of you please help me out?

I thank you in advance


----------



## Prague Hotel (Apr 16, 2009)

Try posting in the html/web forums - they might be able to help out.


----------



## jamiemac2005 (Jul 5, 2007)

It cannot be executed in a browser sorry. No exe could. It could be executed by the server, but the user would not be aware of this (so would not be able to input data). And you could have the user download the exe and execute it on their machine, but what you want to do can't be done.

It's also illogical as you've compiled for linux and the majority of the world use windows, if this were possible you'd be crashing pcs everywhere ;P.

Why do you need it to run like this? it's possible to take the input, then push that into your program using a server side language(e.g. PHP).

Cheers,
Jamey


----------



## rasslove (Apr 14, 2009)

*Thanks*

Hi guys,

Thank you for your reply. I think I'm going to do it as you say: I'll pick up the input in a normal textbox and then push it into my executable. I thought though, that there might be a way (maybe through a java console or something similar) to execute my program from the web. Of course, it'd run on the server (that, as most of the internet servers, would be linux/unix), and a sort of console would be just an interface. I thought that could be possible. However, I'm not an expert. That's why I'm asking here.

Anyway, I think the php/perl solution is the simplest one.

Thanks again.


----------



## jamiemac2005 (Jul 5, 2007)

Hey again, there are ways to do it without re-loading the page but all would use the simple method: Get Input, Send HTTP Request, Inject Input into program. Basically using AJAX/Java you could fool the user into thinking they're using the program but it would be just as complicated as re-writing the program for a different language.

Good Luck coding this, if you need any help please post back =]

Cheers,
Jamey


----------



## jamiemac2005 (Jul 5, 2007)

MegaSpam. Anyone who read the above post, sites like that are registered to by the examining boards who test you and moderate your coursework, the have an index of each of the pieces written and compare your coursework with them. If your coursework has more than an 85% match you get disqualified immediately. if it's more than 60% then you're put up for report, in which they'll question your knowledge on the subject in an interview and can even put you up against a polygraph test. It's easier to read a book and write an assignment than to get through that. Do not click the link.

The site may not even be legitimate, note "david" in the name and yet the end of the message is "cheers! emily"? haha. Spammer's annoy me, someone please remove.


----------



## rasslove (Apr 14, 2009)

*Re: how to put a c++ program in the web ?*

Hi Jamey,

Thanks for you help (your last post was maybe an error, wasn't it?)

Yet I have still some problems. I want to run my c++ program in background by using the command
$cmdstr = "./myc++program > /dev/null 2> /dev/null & echo $!";
$PID = shell_exec($cmdstr);

I need the PID because I want eventually to terminate the program:
exec("ps " . $PID, $state);
if(count($state) >= 2)
**
exec("kill -9 " . $PID);
echo "Program terminated!";
}

The problem is that the condition in the IF (i.e. verifying whether my program is still running) is never fulfilled. This tells me that either a) my program is never started or (even worse) b) my program does run in background, but I can't terminate it.

Can you help me?

Cheers,
Saul


----------



## jamiemac2005 (Jul 5, 2007)

What does $state return?
And does the program not just finish executing and close?

oh and my last post was because a user/bot posted some spam about getting GCSE/A level assignments done online. But that's gone now.


----------



## rasslove (Apr 14, 2009)

*Re: how to put a c++ program in the web ?*

Hi Jamey,

I'm here again. The variable $state returns an array containing the result of "ps"; in the current case, it returns only
PID TTY TIME CMD
that is, only one line, that's the reason why it never enters the IF clause.

Something I didn't mention before is that the php script that start my c++ program and the script that kills it are different files. In the meanwhile, I noticed that this is perhaps the problem. One php script starts the program in background, but once the php file is executed, it automatically terminates my c++ program. Thus, a reasonable question could be whether there is a way to mimic the console command
...> ./myc++program &
so that it keeps running in the background even after I finish the php program. Do you think that "nohup" might do it?

Thanks!


----------



## jamiemac2005 (Jul 5, 2007)

Take a look at this.

It might help. I think that is the problem anyway, and that the post that link takes you to might get around it =]

Cheers,
Jamey


----------



## rasslove (Apr 14, 2009)

Hey Jamey, thanks for your help. My program seems to work properly now. There are still other security issues that I have to fix, but I think that by using SESSIONS all problems will be gone. Thanks again!


----------



## jamiemac2005 (Jul 5, 2007)

Glad to be of help. Glad you got it sorted =]


----------

