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" .

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\" ");

?>
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);

Comments

Your Answer

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.