PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 5th, 2013, 05:27 PM
MynE MynE is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 35 MynE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 32 m 59 sec
Reputation Power: 1
Passing 'string' value to Python Scripts

Hi, I'm looking for a way to pass the string value to my Python Script. My Python script looks like this,

Code:
name = raw_input("Enter your name: ")
print name


And my PHP code is like this:

PHP Code:
<?php 
echo "HelloPython!!";
$output null;
exec('python HelloPython.py'$output$return);
print_r($output);
print_r($return);
?>


<form action="test.php" method="post">
Query Name: <input type ="text" name="Qname">

<input type="submit" value="Confirm">
</form>


What I want to do is I want to enter my name from my PHP page and send that name value to Python script which is 'name'= raw_input("Enter your name here:").
Can somebody please help me find out how can I do this, thank you so much.

Reply With Quote
  #2  
Old March 5th, 2013, 05:50 PM
requinix's Avatar
requinix requinix is online now
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,697 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 4 h 50 m
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
You need to feed something to stdin but exec() won't let you do that. proc_open will.

Untested.
PHP Code:
 $input "HelloPython!!"// you might need a newline

$desc = array(
    
=> array("pipe""r"),
    
=> array("pipe""w"),
    
=> STDOUT
);
$pipes = array();
$p proc_open("python HelloPython.py"$desc$pipes);
if (
$p) {
    
fwrite($pipes[0], $input);
    
fclose($pipes[0]);
    
$output stream_get_contents($pipes[1]);
    
fclose($pipes[1]);

    
print_r($output);
    
proc_close($p);
} else {
    echo 
"Could not run script";


Reply With Quote
  #3  
Old March 5th, 2013, 11:41 PM
MynE MynE is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 35 MynE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 32 m 59 sec
Reputation Power: 1
Thank you for your reply. I dunno why but it doesn't work somehow. I've seen many tutorials like this too, but i still don't understand quite well.

Reply With Quote
  #4  
Old March 6th, 2013, 12:33 AM
requinix's Avatar
requinix requinix is online now
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,697 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 4 h 50 m
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
"Doesn't work" how?

Reply With Quote
  #5  
Old March 6th, 2013, 01:07 AM
MynE MynE is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 35 MynE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 32 m 59 sec
Reputation Power: 1
I'm not sure but I checked $p like this:

PHP Code:
<?php 

$input 
"My name"

$desc = array( 
    
=> array("pipe""r"), 
    
=> array("pipe""w"), 
    
=> STDOUT 
); 
$pipes = array(); 
$p proc_open("python HelloPython.py"$desc$pipes); 
echo 
"It's here";
if (
$p) { 
    echo 
"OK"
} else { 
    echo 
"Could not run script"
}  
?>


I still got the same result "Could not run script", so maybe something is not right on "$p", but I'm not sure now what is it

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Passing 'string' value to Python Scripts

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap