I'm implementing https://github.com/siedi/webpagetest-influxdb .While running the run-tests.sh shell script which takes URL(of a web page) as a a parameter and i want to pass a text file which takes login information.
As mentioned in - https://sites.google.com/a/webpagetest.org/docs/advanced-features/webpagetest-batch-processing-command-line-tool ,i tried to write my URL to an external file and used --urlfile=/foo/urls.txt (like sh run-tests.sh --urlfile=/foo/urls.txt) which is in Python.
Above method in SH is not seem to be working
Can anyone help me on how can i pass these two files along with sh command if its possible.
Related
I'm currently trying run the shell script by using the os.system method in python.
Python code:
file = open("History.txt","w")
file.write(history)
os.system('./TFPupload.sh')
Shell script code:
#!/bin/sh
HOST="ftp.finalyearproject95.com"
USER='*****'
PASSWD='*****'
FILE='History.txt'
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
put $FILE
quit
END_SCRIPT
echo ">>>uploaded<<<\n"
exit 0
At first, when i tried to run the python code and shell script one by one it works perfectly. However, when i attempt to use python to run shell script, instead of uploading the 'History.txt' file that contains data into the database, the file uploaded is an empty file. When i check using 'nano History.txt', it does contain data, only when it passes the text file to the database will be empty. Why is it?
Use With statement to open files whenever possible .
with open("History.txt","w") as file :
file.write(history)
os.system('./TFPupload.sh')
with statement takes care of closing the fd on its own .
some Ref : What is the python "with" statement designed for?
so i checked several other links with similar titles but, It couldn't solve my specific question. I'm trying to run a python file in notepad++ which is not a problem to me however, this file takes in a few things in order for it to compile. This is how I successfully run it in the command prompt.
python upload.py --file= "video path" --title= "title" --description= "testing"
My question is, how would i set these attributes in a different python file and then just call that file instead?
here is my code that i have in my new file
Thanks
enter image description here
enter image description here
You can use the subprocess module to do this. Following the example from the docs and the code you've listed:
import subprocess
result = subprocess.check_output('python upload.py --file="video path" --title="title" --description="testing"')
result will store any output from your command.
Note: if you're running in a windows environent, not linux, change the /usr/bin/python to python.
Maybe you can use subprocess to call your specific command.
In a separate file in the same folder, you can put a file like this:
import subprocess
subprocess.call("python upload.py --file= \"video path\" --title= \"title\" --description= \"testing\"")
And then you just call that file, and that's it...
Here is the code I have so far:
How can I make this program open another python file, using this method or similar (you have to open it from a variable)?
You can use exec function, for to execute an external script,
file = "test.py"
exec(open(file).read())
you get,
File Opened!
I'm calling Microsoft Ajax Minifier from Python like so:
minifyArguments = ["C:\Program Files (x86)\Microsoft\Microsoft Ajax Minifier\AjaxMin.exe"]
for f in filesToMinify:
minifyArguments.append(f)
minifyArguments.append("–out")
minifyArguments.append("C:\\Users\\XXX\\Desktop\\TestFolder") #minifyJSDestinationPath
minifyArguments.append("–clobber")
ajaxMinProcess = subprocess.Popen(minifyArguments, shell=False)
stdout, stderr = ajaxMinProcess.communicate()
This works fine, and I see that it's starting etc. but when it wants to write the output file it gives an error:
AjaxMinifier.exe: error AM-AUTH: Access to the path 'C:\Users\XXX\Desktop\TestFolder' is denied.
I have tried different folders, the issue is not exclusive to the one in the code. It can't write to any folder.
When I don't call it from Python but directly from the commandline it works without problems.
Why does this happen and how can I fix it?
Thanks.
I found the solution to my problem:
This line:
minifyArguments.append("C:\\Users\\XXX\\Desktop\\TestFolder")
Should include the filename, like this:
minifyArguments.append("C:\\Users\\XXX\\Desktop\\TestFolder\\script.min.js")
I want to use osmconvert to parse down the size of my diff files for just the area I'm interested in because osmconvert is way faster than osm2pgsql, which loads the data.
When I call the command using os.system() like such:
cmd = r"""c:\temp\osmconvert.exe 770.osc.gz -b=1,1,3,3 -o=extract.o5m"""
os.system(cmd)
I get osmconvert error: cannot open file
When I run the same exact command from my command prompt in Windows 7, it runs fine. What is python doing to prevent this function from running? The 770.osc.gz file lives in the same directory as osmconvert.exe and the output extract.05m should populate in the same directory as the osmconvert.exe exists.
If I put the command in a batch file, it works, but I want to use python to download the file from the server so I can automate the updates of the database.
Thank you
The 770.osc.gz file lives in the same directory as osmconvert.exe and the output extract.05m should populate in the same directory as the osmconvert.exe exists.
That's not what your code is saying. The code says "execute osmconvert.exe from inside c:\temp\ but read 770.osc.gz and write extract.o5m from the current working directory".
If you want everything to run inside c:\temp\ then you either have change to this directory before executing osmconvert or you have to preprend the path to every file you are passing to osmconvert.
Try this call instead:
cmd = r"""c:\temp\osmconvert.exe c:\temp\770.osc.gz -b=1,1,3,3 -o=c:\temp\extract.o5m"""