Executing python script with pdflatex using PHP on Ubuntu webserver? - python

I am trying to execute a python script which uses pdflatex using php. Running the python script via command line works well.
But if I try to call it with php, it throws this error:
I can't write on file mylatex.log'. (Press Enter to retry, or
Control-D to exit; default file extension is `.log') Please type
another transcript file name: ! Emergency stop ! ==> Fatal error
occurred, no output PDF file produced!
So there seems to be a permission error.
This is the way I am trying to call the php file:
$command = escapeshellcmd('python3 /home/ubuntu/test.py');
$output = shell_exec($command);
echo $output;
The mylatex.log file has 777 permission as a test.
Is there a way to execute a python script which uses a library like pdflatex?

I solved the error by adding the php file to the same directory as the python file. Then it works. There seems to be a problem to call pdflatex in a different directory. Thanks for the help.

Related

How to call Python Script from class in Symfony

I'm wondering how I can call a python script from a class in Symfony. I keep getting an error that it can't locate the script.
May 28 13:54:13 |INFO | PHP python: can't open file 'Request.py': [Errno 2] No such file or directory
The code is as followed:
$python = shell_exec("python Request.py");
echo $python;
The script is outside the symfony project, but I'm not quite sure how to get the path relative to the class file.
$path = shell_exec("pwd");
echo $path;
Should show you your current directory.
And I would suggest using Symfony Process Component https://symfony.com/doc/current/components/process.html

couldn't execute "python": no such file or directory

I am trying to execute python from tcl script but i have the message error "couldn't execute "python": no such file or directory"
This is my code:
test.py
print('hello')
exec.tcl
set out [exec python test.py]
puts $out
and in Windows PowerShell i use this command:
tclsh exec.tcl
Could you please help me fix this error?
Depending on your Python's version, it may use py as command. You should try using 'py' instead of 'python'.
More info:
Python Launcher for Windows (Python Docs)

Executable .py file with shebang path to which python gives error, command not found

I have a self-installed python in my user directory in a corporate UNIX SUSE computer (no sudo privilege):
which python
<user>/bin/python/Python-3.6.1/python
I have an executable (chmod 777) sample.py file with this line at the top of the file:
#!<user>/bin/python/Python-3.6.1/python
I can execute the file like this:
python sample.py
But when I run it by itself I get an error:
/full/path/sample.py
/full/path/sample.py: Command not found
I have no idea why it's not working. I'm discombobulated as what might be going wrong since the file is executable, the python path is correct, and the file executes if I put a python command in the front. What am I missing?
EDIT:
I tried putting this on top of the file:
#!/usr/bin/env python
Now, I get this error:
: No such file or directory
I tried this to make sure my env is correct
which env
/usr/bin/env
EDIT2:
Yes, I can run the script fine using the shebang command like this:
<user>/bin/python/Python-3.6.1/python /full/path/sample.py
Your file has DOS line endings (CR+LF). It works if you run python sample.py but doesn't work if you run ./sample.py. Recode the file so it has Unix line endings (pure LF at the end of every line).
Try using #!/usr/bin/env python as described in this post. Let the OS do the work.

executing a .sh file from python indicating an absolute path

im kinda new to the python world and im having some issues running a bash file that will be automatically from my python script (using linux) .
i set my python script to create both a text file .geo and a Bash file .sh in a directory somewhere in my Desktop like this :
basedirectory="/home/pst2/Desktop/";
*//Writing the .geo file*
file = open(basedirectory+nomdossier+"/"+nomfichier+".geo", 'w');
file.write
..blabla
..blabla
file.close();
//Writing the .sh file
file = open(basedirectory+nomdossier+"/"+nomfichier+".sh", 'w');
file.write
..blabla
..blabla
file.close();
Now at this point my script works perfectly with all the variables set up and working fine and both those files that i created find themselves in this directory (for exemple after running the python script and entering the variables)
/home/pst2/Desktop/test/
(and in here you will find the new test.geo and test.sh that were created via the python script)
basically the test.sh when executed "manually" with Bash test.sh ( whenever i am in its directory on ubuntu) will create another file called test.msh in the same directory
and i cant seem to find the right coding , using the subprocess modules to execute the newly created test.sh file automatically from the script .
is there a way to do so , like with indicating the absolute path to the .sh file
(in our case basedirectory+nomdossier+"/"+nomfichier+".sh ) ?
take a look at the os module.
I believe
os.system("command_line_with_args")
could be what your looking for
Not sure what you are writing into the .sh file.
But to start with:
Have you started your .sh-file with the hashbang? #!/bin/sh
Have you modded your file as executable? chmod +x
After you have done this, you should be able to use subprocess module and do something like the example from the manual for subprocess:
subprocess.call([path_to_script+'/script.sh'])
I might have to update this answer if & when new information comes to my attention
Roughly equivalent to "manually" executing bash test.sh with the current directory being the one where test.sh has been written by your posted code is:
from subprocess import call
call(['bash', 'test.sh'], cwd=basedirectory+nomdossier)

How to run wlst script by .py file

I'm trying to run wlst script form .py file but it can not be done
Content of .py file :
connect('weblogic','weblogic','t3://localhost:8001')
sca_undeployComposite('http://localhost:8001','Hello','1.0','user='weblogic',partition='myPartition')
sca_deletePartition('myPartition')
sca_createPartition('myPartition')
sca_deployComposite('http://localhost:8001','C:\WLST\Test\Application.zip',user='weblogic',configplan='myPlan.xml', partition='myPartition')
exit()
when i run cmd file to execute script, Only connect() method is execute success. any command bellow it can not be execute. And error message appear: Problem invoking WLST - Traceback (innermost last): File "c:\WLS\script\filname.py", line 2, in ?
Name Error: sca_undeployComposite
Please help me to resolve it. Thanks !
The commands after the connect() line which are not regular WLST commands. They requires sca related libraries into CLASSPATH. if you look into your wlst.cmd or .sh file that is actually calling the environment setup file that could be setWLSEnv.sh/.cmd. If you run that from where you are having the this python script. That script will work, it is simple java CLASSPATH funda nothing else!
Probably you might be running wlst.cmd after navigating to the common bin folder like
cd /oracle/fmwhome/Oracle_SOA1/common/bin/.
instead you can run in your script like this
C:\WLS\script\>/oracle/fmwhome/Oracle_SOA1/common/bin/wlst.cmd filename.py
or
C:\WLS\script\>/oracle/fmwhome/Oracle_SOA1/common/bin/setWLSEnv.cmd
C:\WLS\script\>java weblogic.WLST filename.py
You can also refer for more sca related scripting: WLSTByExamples

Categories