I have tried to run the Github: https://github.com/atbaker/wikipedia-question-generator
I have created the virtual environment using the following instruction: https://github.com/atbaker/wikipedia-question-generator#installing-with-python-34
$ pyvenv venv
$ source venv/bin/activate
$ pip install -r requirements.txt
$ python -m textblob.download_corpora
Install the command line tool so you can use the tool easily:
$ pip install -e folder_name
Now the environment is completed.
My code ran properly on the commandline using the following:
wikitrivia 'tony'
Now I have tried to use it using php shell script as follows:
<? php
$out = shell_exec('wikitrivia "tony" ');
echo $out;
?>
But there is nothing on the output screen. I tried to run the command php -v and have shown the version. But the command wikitrivia "tony" is not working. I am using AWS Ubuntu environment.
My php version is 7 and the python version is 3.5
Hope this helps. Kindly, let me know what I can do?
I did it recently as a cron task.
You need to execute script from working dir with interpreter from venv.
Somethin like that:
<? php
$out = shell_exec('cd FULL_YOUR_PYTON_WORKING_DIR && YOUR_VENV/bin/python FULL_PATH_TO_YOUR_SCRIPT.py "tony"');
echo $out;
?>
Related
I have a shell script (called test.sh) which is called from PHP. Within the script I simply have:
#!/bin/bash
echo $(whoami)
cordova platform version ios
If I call test.sh from within terminal it works fine and returns the cordova ios version.
If I try to call test.sh from with PHP I get:
cordova: not found
I have altered apache to run under my username instead of _www but that hasnt worked.
Can anyone point me in the right direction as I'm guessing it is a permissions issue?
I have now simplified it further by removing the .sh file and just using the PHP script (under user _www)
exec('echo $(whoami) 2>&1', $output, $return_var);
print_r($output);
echo "<br><br>";
putenv("CORDOVA_HOME=/usr/local/bin/cordova");
exec('cordova -v 2>&1', $output, $return_var);
print_r($output);
Note: whoami works fine but corvoda is still not found.
Use npm to install Cordova globally. right now Cordova is not available in your host globally. So make it globally first.
on OS X and Linux:
sudo npm install -g cordova
on Windows:
C:\>npm install -g cordova
To solve the problem I looked at the path returned from terminal and PHP, they were both using the same username but returned different path details.
After adding to PHP:
putenv("PATH=".getenv('PATH').":/Users/USERNAME/.sdkman/candidates/gradle/current/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands");
putenv("CORDOVA_HOME=/usr/local/bin/cordova");
It began to work. I now have a problem with finding certificates but that will be a different question after investigating it.
I'm trying to run a python script through my PHP page. when the script runs the output states that my modules does not exist. I am using exec("python3 sciprtname.py arg1 arg2") I have installed these modules using pip3. when I write the same command in terminal it runs properly.
ModuleNotFoundError: No module named 'pdfkit
I have tried several approaches but none succeeded:
tried escapeshellcmd() shell_exec()
#!/usr/bin/env python
chmod +x myscript.py
Any Help would be appreciated. Thanks in advance.
You need to check if pdfkit is already installed or not. To install it with pip3
pip3 install pdfkit
In PHP running on Ubuntu, I can run exec('npm -v') and the output is good,
but I can't run exec('gitbook xxxx').
gitbook is a npm package I installed by
npm install gitbook -g
I can run gitbook xxxx in the Ubuntu terminal, how can I run it from my PHP code?
If you run php by nginx or apache (for example, visit url example.com/index.php), sometime you need to export the PATH
exec("export PATH=/usr/local/bin && gitbook build);
after I added export PATH, everything works fine.
I tried once like this on UNIX-based OS:
You can run shell commands via the exec() function:
// make an php file to execute shell script
exec("node yourscript.js &", $output);
Well output here become array of each line of output along with process id. You can kill process by processid also.
exec("kill " . $processid);
This how I was did. Other then this you can use node supervisor. Hope it will help you. Try your also with node command.
Windows 10 just released Anniversary Update today. Now you can use Ubuntu flavored bash command from Linux subsystem.
The question is: How to execute Windows10's Bash command from PHP?
I tried
<?php
exec('bash',$out1,$result1);
exec('ls -l',$out2,$result2);
var_dump($out1);
var_dump($result1);
var_dump($out2);
var_dump($result2);
It doesn't work. All $out are empty array, and both $results are 1.
Any idea?
Just found out that I can run web server directly from subsystem.
e.g.
$ sudo apt-get install apache2
$ sudo service apache2 start
Then put all web contents inside subsystem's directory located at %localappdata%\Lxss\rootfs
At this point I can execute bash script however I want.
You can not. Ubuntu on Windows is implemented as a different subsystem directly below the Windows Kernel. So it runs separate to normal Windows processes and can not interact with them. (At least that is how I understand it). But maybe you just have to use C:\Windows\System32\bash.exe as the command.
Bash is not meant to be used to run a server but you can run PHP-CLI on bash without an issue.
Instead of running the PHP script in Windows and then accessing bash it would be easier to create a command to run the PHP script directly in bash.
So you would run `bash.exe -c "php path/to/php-script.php"
https://blogs.msdn.microsoft.com/commandline/2016/10/19/interop-between-windows-and-bash/
I have installed PHP CLI to execute php commands from console.
I have installed PHP CLI using this command -
sudo apt-get install php5-cli
When I run this
$vr=3; echo $vr;
Result :-
=3: command not found
If I run echo "test";
Result :- test
displays..
Can anyone tell why "command not found" displays..
The "echo "test" line is working because echo is a bash command.
You have to write your own php script, the run it by command line like this:
$ php myscript.php
In alternative, you can run php from your command line, then directly write or paste your script.
Then press CTRL+D to run it. Remember the at the beginning and at the end.
As third option, you can write a php script, putting in the first line this code:
#!/usr/bin/php
Obviously the php executable path must match the one in your system.
This way, you can chmod +x the script, then run it directly like this:
$ ./myscript.php
The fourth option is the interactive shell:
$ php -a
Interactive shell
php > echo 5+8;
13
[$ in front of commands means a command run by user]
You are entering PHP code into the Unix shell (e.g. bash). The Unix shell does not understand PHP code, so you have to run php first.
To run your PHP code from the command line:
$ php -r '$vr=3; echo $vr, "\n";'
3
To run your PHP code from the PHP interactive shell (which may or may not be compiled into PHP):
$ php -a
Interactive shell
php > $vr=3; echo $vr, "\n";
3
php >
(Hit Ctrl+D or type exit to get out of the PHP shell.)
To run your PHP code from a file named prog.php (which contains <?php before the code):
$ php prog.php
3
It seems you want something like this: http://www.php.net/manual/en/features.commandline.interactive.php
This gives you an interactive mode, where you can type PHP code and have it executed directly.