Running different Programs under 1?

For the discussion of Perl, Python, Ruby, and PHP and other interpreted languages.

Running different Programs under 1?

Post by -Ninjex- on Fri Jan 18, 2013 2:35 am
([msg=72343]see Running different Programs under 1?[/msg])

Hey guys!
I have a quick question, after I give a bit of background of myself.
The languages I know include:
HTML, CSS, JavaScript, PHP, Python, with a splash of knowledge on SQL.

So yeah, my programming background isn't the best. I plan on finishing SQL soon and then diving into either C++, Java, or Perl afterwards. I am not sure which one I will choose just yet.

So throughout all of my time learning these languages, (I may be using bad sources to learn from) I haven't been able to find a way to run or call on another program with a different extenstion to execute from within another.

For instance, if I had three files, test.py, test2.py, and test.pl in the same directory and tried the code below, it would not work. Assume the code below belongs to test.py and we run both python and perl as our choice for the program type. Of course the python program (test2.py) will work fine. The perl program, (test.pl) on the other hand will not. This is because it tries to pass the file and execute it as python. Does anyone know of a way to prevent this? It's been bugging me for a while now, and I want to get this stuff down better before tackling the programming challenges on this site.

Code: Select all
program = raw_input("Which program type would you like to start?" + "\n")
starting = "Starting program" + ": " + program 
if program == "python":
        print(starting)
        execfile("test2.py")
elif program == "perl":
        print(starting)
        execfile("test.pl")
else:
        print("Program type could not be found")


If possible, I need to know how to do this on a website. This will give it almost a GUI based feel, because it is running from the website. Such as having a input section for commands / parameters, and then a button to click that will execute the code. I am not sure if this is possible to do. If you know how you would go about making a GUI application that can run the different file types, that will work as well. In short, I know these languages, but I don't know how to bring them together or onto a single application or website. I wish to figure this out to test this on my apache server.

I have a .sh file that checks for loadbalancing, and perl script used to dos the site.
First it should execute the .sh file, and if the condition (site loadbalancing == false) is met, it needs to run the perl script. This will be used on my own apache server on another local machine; strictly pen testing.

[Edit] I realized that I can use bash files with the following command:
Code: Select all
import os
os.system('./file-name.sh')


Note: I am aware of the existence of PyQt

I would still like to know how to allow any file types to be executed.
Thanks in advance,
- Ninjex
If you're not willing to learn, no one can help you. If you're determined to learn, no one can stop you.⠠⠵
The absence of evidence is not evidence of absence.
I can explain it for you, but I can't understand it for you.
^(-.^)>
User avatar
-Ninjex-
Addict
Addict
 
Posts: 1468
Joined: Sun Sep 02, 2012 8:02 pm
Blog: View Blog (0)


Re: Running different Programs under 1?

Post by tgoe on Sat Jan 19, 2013 5:41 pm
([msg=72377]see Re: Running different Programs under 1?[/msg])

execfile() is only for python. You probably want the subprocess module. Although limited, os.system() will work.

For the website stuff you want CGI.

When it comes to language choices you'll want to pick languages that are radically different. i.e., if you're a ruby guy you won't be learning as much from python vs something lower like C or assembly or something weird like erlang :)
User avatar
tgoe
Contributor
Contributor
 
Posts: 664
Joined: Sun Sep 28, 2008 2:33 pm
Location: q3dm7
Blog: View Blog (0)


Re: Running different Programs under 1?

Post by -Ninjex- on Sat Jan 19, 2013 7:23 pm
([msg=72381]see Re: Running different Programs under 1?[/msg])

tgoe wrote:execfile() is only for python. You probably want the subprocess module. Although limited, os.system() will work.

For the website stuff you want CGI.

When it comes to language choices you'll want to pick languages that are radically different. i.e., if you're a ruby guy you won't be learning as much from python vs something lower like C or assembly or something weird like erlang :)


Hey, Tgoe! Thanks for the response. I actually looked into and tried what you said above before, only to get fails, for reason I am not sure of... Hence why I thought it wasn't possible.

Here is a look at the main python script "test.py"

Code: Select all
#! /usr/bin/env python
import subprocess
import os
program = raw_input("Which program type would you like to start?" + "\n")
starting = ("Starting program" + ": " + program)
if program == "python":
        print(starting)
        execfile("test2.py")
elif program == "perl":
        print(starting)
        return_code = subprocess.call("/home/jjjj/Desktop/test.pl", shell=True)
else:
        print("Program type could not be found")


I then run the commands below:

Code: Select all
jjjj@Ninjex:~/Desktop$ sudo python test.py
Which program type would you like to start?
perl
Starting program: perl
/bin/sh: 1: /home/jjjj/Desktop/test.pl: Permission denied
jjjj@Ninjex:~/Desktop$


Aslo, I was looking into cgi and everything seemed well, until I went to my page after cgi-bin and I got a error message saying that I I was unable to access the page. Although that is due to my poor understanding of cgi-bin, so I will look into it a bit more so that I can fix it.

[Edit] I decided to take on C++ although so far it seems really similar to JavaScript and Python, with slight exceptions to syntax of course.

Thanks again,
- Ninjex
Last edited by -Ninjex- on Sat Jan 19, 2013 7:46 pm, edited 1 time in total.
If you're not willing to learn, no one can help you. If you're determined to learn, no one can stop you.⠠⠵
The absence of evidence is not evidence of absence.
I can explain it for you, but I can't understand it for you.
^(-.^)>
User avatar
-Ninjex-
Addict
Addict
 
Posts: 1468
Joined: Sun Sep 02, 2012 8:02 pm
Blog: View Blog (0)


Re: Running different Programs under 1?

Post by tgoe on Sat Jan 19, 2013 7:46 pm
([msg=72385]see Re: Running different Programs under 1?[/msg])

Don't use sudo while you're just dicking around! LOL

chmod +x /home/jjjj/Desktop/test.pl (assuming the proper hashbang)

Yeah... C++... Don't do it unless you're gettin paid :)
User avatar
tgoe
Contributor
Contributor
 
Posts: 664
Joined: Sun Sep 28, 2008 2:33 pm
Location: q3dm7
Blog: View Blog (0)


Re: Running different Programs under 1?

Post by LoGiCaL__ on Sun Jan 20, 2013 5:37 pm
([msg=72415]see Re: Running different Programs under 1?[/msg])

tgoe wrote:Yeah... C++... Don't do it unless you're gettin paid :)


I lol'd when I read that. But yeah, it's somewhat true although sometimes you got to go back to your roots and do some ninja training.
User avatar
LoGiCaL__
Addict
Addict
 
Posts: 1063
Joined: Sun May 30, 2010 12:33 pm
Blog: View Blog (0)


Re: Running different Programs under 1?

Post by -Ninjex- on Sun Jan 20, 2013 6:13 pm
([msg=72418]see Re: Running different Programs under 1?[/msg])

tgoe wrote:Don't use sudo while you're just dicking around! LOL

chmod +x /home/jjjj/Desktop/test.pl (assuming the proper hashbang)

Yeah... C++... Don't do it unless you're gettin paid :)



You have to be kiding me...
It was just the permissions on the file, thanks again.
I really didn't think about it because running the perl file on it's own was fine. Now I know that when trying to access a file from another I should check permissions and make sure it's executable.

I only tried to sudo because I was getting the permission denied error as you can see above.
That's why I tried sudo after a regular run.

As for C++ I was looking at elance.com and C++ could come into handy...
Seems pretty easy to learn anyways, due to it's similarity with JavaScript and Python (so far)
If you're not willing to learn, no one can help you. If you're determined to learn, no one can stop you.⠠⠵
The absence of evidence is not evidence of absence.
I can explain it for you, but I can't understand it for you.
^(-.^)>
User avatar
-Ninjex-
Addict
Addict
 
Posts: 1468
Joined: Sun Sep 02, 2012 8:02 pm
Blog: View Blog (0)


Re: Running different Programs under 1?

Post by centip3de on Sun Jan 20, 2013 9:05 pm
([msg=72421]see Re: Running different Programs under 1?[/msg])

-Ninjex- wrote:You have to be kiding me...
It was just the permissions on the file, thanks again.
I really didn't think about it because running the perl file on it's own was fine. Now I know that when trying to access a file from another I should check permissions and make sure it's executable.

I only tried to sudo because I was getting the permission denied error as you can see above.
That's why I tried sudo after a regular run.

As for C++ I was looking at elance.com and C++ could come into handy...
Seems pretty easy to learn anyways, due to it's similarity with JavaScript and Python (so far)


I'm a bit tardy to the party, but based off of your background, I would actually suggest using Java and then moving over to C++, then C, then NASM. Because C++ is forced to be backwards compatible with C, it has a bit of a wonky syntax, and can't abstract everything to the level someone like you would be used to. However, Java doesn't follow such an odd paradigm, so it might feel a bit more like home to you.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rick Cook
User avatar
centip3de
Moderator
Moderator
 
Posts: 1449
Joined: Fri Aug 20, 2010 5:46 pm
Blog: View Blog (0)


Re: Running different Programs under 1?

Post by -Ninjex- on Sun Jan 20, 2013 9:56 pm
([msg=72426]see Re: Running different Programs under 1?[/msg])

centip3de wrote:I'm a bit tardy to the party, but based off of your background, I would actually suggest using Java and then moving over to C++, then C, then NASM. Because C++ is forced to be backwards compatible with C, it has a bit of a wonky syntax, and can't abstract everything to the level someone like you would be used to. However, Java doesn't follow such an odd paradigm, so it might feel a bit more like home to you.


Thanks, I have full days free to learning. I am at the point of OOP for C++ and still feels the same, so I could probably just switch to java and use a syntax reference when/if I need to program in C++

You and tgoe basically said the same, so I will move along to something new.

Thanks for the input everyone it is much appreciated.

- Ninjex
If you're not willing to learn, no one can help you. If you're determined to learn, no one can stop you.⠠⠵
The absence of evidence is not evidence of absence.
I can explain it for you, but I can't understand it for you.
^(-.^)>
User avatar
-Ninjex-
Addict
Addict
 
Posts: 1468
Joined: Sun Sep 02, 2012 8:02 pm
Blog: View Blog (0)


Re: Running different Programs under 1?

Post by fashizzlepop on Mon Jan 21, 2013 12:28 am
([msg=72431]see Re: Running different Programs under 1?[/msg])

If you're understanding c++ now then don't switch to java just because cent suggested it. If anything Java will be easier after learning c++ than the other way around. C++ doesn't take care of garbage collection like Java does.

Also have no idea how you think python and c++ are similar.
The glass is neither half-full nor half-empty; it's merely twice as big as it needs to be.
User avatar
fashizzlepop
Developer
Developer
 
Posts: 2303
Joined: Sat May 24, 2008 1:20 pm
Blog: View Blog (0)


Re: Running different Programs under 1?

Post by -Ninjex- on Mon Jan 21, 2013 2:06 am
([msg=72442]see Re: Running different Programs under 1?[/msg])

fashizzlepop wrote:If you're understanding c++ now then don't switch to java just because cent suggested it. If anything Java will be easier after learning c++ than the other way around. C++ doesn't take care of garbage collection like Java does.

Also have no idea how you think python and c++ are similar.



Honestly to me, Python and C++ seem pretty similar, but I am weird so who knows...
They are slightly different in their own ways, and I feel that c++ gives a bit more to work with.
And maybe it's just me, but JavaScript, Python, and C++ feel pretty much the same in syntax.
I will not drop C++, I think it is fun; I tried looking for good java tuts to come up empty handed. So in return, I just spent about 2 hours writting my first actual small program on C++ and decided to go ahead and finish seeing it through.
I honestly do not see C++ taking me that long to figure out, so it shouldn't be long before I hop onto the java bandwagon anyways.
If you're not willing to learn, no one can help you. If you're determined to learn, no one can stop you.⠠⠵
The absence of evidence is not evidence of absence.
I can explain it for you, but I can't understand it for you.
^(-.^)>
User avatar
-Ninjex-
Addict
Addict
 
Posts: 1468
Joined: Sun Sep 02, 2012 8:02 pm
Blog: View Blog (0)


Next

Return to Interpreted Languages

Who is online

Users browsing this forum: No registered users and 0 guests