0

i have problem , i want to passing variable from php to python . why if my word contains space , in python cannt receive this words . Example Code :

<?php 
$variable = "Test Variable Contains Space";
echo shell_exec("C:\Users\HP\AppData\Local\Programs\Python\Python37-32\python.exe C:\Users\HP\AppData\Local\Programs\Python\Python37-32\hasil.py $variable ");
?>

in my python code :

import sys
variable = str(sys.argv[1])
print variable

the result i have from this code jut this words "Test" .

asked Nov 26, 2018 at 2:39
1
  • escapeshellarg is usually the best option. Albeit cmd might mess with it, Python usually employs a standard shell argument tokenizer. Commented Nov 26, 2018 at 2:51

2 Answers 2

1

Bash commands interpret arguments as separated by spaces, therefore, Test Variable Contains Space seems like 4 different arguments. To fix this, you need to surround it with double quotes:

... \"$variable\" ");

Full code:

<?php 
$variable = "Test Variable Contains Space";
echo shell_exec("C:\Users\HP\AppData\Local\Programs\Python\Python37-32\python.exe C:\Users\HP\AppData\Local\Programs\Python\Python37-32\hasil.py \"$variable\" ");
?>
answered Nov 26, 2018 at 2:44
Sign up to request clarification or add additional context in comments.

Comments

0

Please add "." after url part is completed.

echo shell_exec("C:\Users\HP\AppData\Local\Programs\Python\Python37-32\python.exe C:\Users\HP\AppData\Local\Programs\Python\Python37-32\hasil.py". $variable);
answered Nov 26, 2018 at 4:25

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.