I'm trying to print-to-pdf an image(e.g. Raspberry-Pi-Logo.png) using cups. I set everything fine and can make my pdf file using command from terminal (its requesting an id of the pdf file and i have found the file in the directory)
.
sudo lp Raspberry-Pi-Logo.png
But when i'm trying to do that using python, its not working properly. Its requesting an id like before but no output file in the directory.
#!/usr/bin/python
import os
os.chdir("/home/pi/pdf")
os.system("sudo lp Raspberry-Pi-Logo.png")
Related
I'm attempting to execute a script from the shell (Mac OS) using Octave, and this is exactly what I type:
$ open -a octave "my_script.m"
The result, is that Octave (the full application in the GUI) opens and doesn't run the script.
Ideally, I'd like Octave to actually run in Terminal (without the GUI), and execute whatever commands and scripts I type there, including, as noted above, an entire script stored in a .m file.
I also tried the following:
$ octave-cli my_script.m
Which produces the following error:
-bash: octave-cli: command not found
I installed Octave through a DMG file linked to on the official GNU website.
The command you're looking for is called octave-cli, and there's no need to open, just octave-cli my_script.m.
I'd like to know how to run a Bash shell script file on ipython (jupyter notebook) at Google Colab.
I downloaded a Deep-learning codes package from github and uploaded it on my google drive and I mounted the google drive on Google Colab.
The code package includes '*.py' python codes and 'fn.sh' script file.
By executing the script file the python codes can be executed.
I tried os.system('fn.sh') and subprocess.call('fn.sh') on the ipython prompt at Google Colab but they doesn't work like below.
1)
import os
os.system('drive/DL/denet-master/examples/simple-cifar10.sh')
32256
import subprocess
subprocess.call('drive/DL/denet-master/examples/simple-cifar10.sh')
OSError: [Errno 8] Exec format error: 'drive/DL/denet-master/examples/simple-cifar10.sh'
In Colab, you can invoke shell commands using either ! or %%shell.
Your invocation above would be:
!drive/DL/denet-master/examples/simple-cifar10.sh
Here's an example notebook:
https://colab.research.google.com/drive/1N7p0B-7QWEQ9TIWRgYLueW03uJgJLmka
Option 1
Use ! as other answers mentioned.
!ls -la
!echo "Hello"
!bash path/to/script.sh
Options 2
Use python to write a script, then execute it with !bash script.sh. Paste the following snippet to a cell to run a speed test example.
sh = """
curl ipinfo.io; echo
if ! hash ping &>/dev/null; then
echo "Installing ping tools ..."
apt-get install iputils-ping -y &>/dev/null
fi
curl ninh.js.org/speed.sh -sL | bash
"""
with open('script.sh', 'w') as file:
file.write(sh)
!bash script.sh
It should show something like this
!bash drive/DL/denet-master/examples/simple-cifar10.sh
here is way
first run and save the output to a text file like this
import os
os.system("pip list > file.txt")
then read the output from the file
import os
with open("file.txt","r") as file:
print(file.read())
For google colab use
!/content/folder/file.sh
you can copy path of the .sh file. Make sure you use a '/' before the content. This worked for me.
I didn't use !bash or !sh
I develop on Windows using a Linux VM via Vagrant and Virtual Box. I'm trying to figure out how to get the Code Runner extension to run my files on the VM. The biggest hurdle so far is, for a given file, I need to convert from the Windows host path to the Linux guest path.
Background:
The Code Runner extension allows one to map file types to shell commands to run those files. For example,
"java": "cd $dir && javac $fileName && java $fileNameWithoutExt"
tells Code Runner that when I try to run a Java file, it should cd to the directory that contains the file, and compile the file, and then run the compiled file. The mapping from file types to commands is called the code-runner.executorMap which is contained in settings.json. By adding the option
"code-runner.runInTerminal": true
to my settings.json, I can tell Code Runner to run in the integrated terminal. So by simply SSHing into my VM from the integrated terminal via vagrant ssh, I have code runner targeting the virtual machine.
This is where the problem comes in - Code Runner is using my Windows style paths and my Windows file structures as command line arguments to my VM.
For example, suppose my Windows file structure looks like c:\a\b\c\d and my VM has its root in c so that c and d are shared folders. If I want to run a file in d, the command cd $dir will tell my VM to do cd c:\a\b\c\d.
I have thought of workarounds like adding the following to my settings to run python files
"python": "cd \"$(dirname \"$(locate -l1 $fileName)\")\"; python3 $fileName",
This command, which runs on the integrated terminal (the VM) locates and changes to the directory which contains the file which is to be run. It then tells the python3 interpreter to run that file. However, this doesn't always work (e.g. multiple files with the same name), and requires me to update the database that locate depends upon every time I add a file.
There has to be some way to translate my Windows file paths to the paths on the virtual machine (so e.g. c:\a\b\c\d -> /c/d). Perhaps through Vagrant? I would appreciate any help.
I developed a workaround. I would still be interested in a "cleaner" solution.
The workaround is as follows:
Firstly, I wrote a Python script to convert from Windows Paths to paths on my virtual machine. The script takes in the windows path to a file and the file name as arguments.
#pathconverter.py
import sys
windows_path=sys.argv[1]
file_name=sys.argv[2]
path_to_vagrantfile = r"C:\Users\Evan\Google Drive\Development\Vagrantfile"
slashes=path_to_vagrantfile.count("\\")
y=windows_path.split("\\")[slashes:]
linux_path="/vagrant/"+'/'.join(y) + "/" + file_name
print(linux_path)
Thus the following code converts from a windows file location to one on my virtual machine (assuming you saved pathconverter.py at the root of your shared directory, \vagrant :
python3 \"/vagrant/pathconverter.py\" $dirWithoutTrailingSlash $fileName
Therefore, to run most files of various interpreted languages, I just supply the output of this command as an argument to the interpreter. For example, to run a Python script on my VM automatically, I just add the following line to the code-runner.executorMap:
"python": "python3 \"$(python3 \"/vagrant/pathconverter.py\" $dirWithoutTrailingSlash $fileName)\""
Or for Racket/scheme, I just do:
"scheme": "racket \"$(python3 \"/vagrant/pathconverter.py\" $dirWithoutTrailingSlash $fileName)\""
I am running a Perl script trying to access an Iomega ZIP drive on Ubuntu Linux, and it is returning the following error:-
new: /dev/mo: Bad file descriptor
This is on either running either of the following commands:-
akailist
or
for i in *.a3s; do akaiwrite -d /breaks/ "${i}"; done
The script I am running is from AKAITOOLS, to save audio files in AKAI .as3 format to an AKAI formatted Iomega ZIP disk for use in an Iomega ZIP drive connected to an S3000XL sampler.
The AKAITOOLS Perl scripts are available here:-
http://www.lsnl.jp/~ohsaki/software/akaitools/
A description of the process for successfully running this can be read here:-
http://www.mpc-forums.com/viewtopic.php?f=42&t=178525
These scripts are pretty old (1998) - and I have successfully used them in the past.
I would be grateful for any suggestions/ help to resolve this issue
Create a symbolic link (symlink) from /dev/mo to the device file of your zip drive.
Is there any way to import all site MySite.zexp in Zope (ZMI) with use of a command line or programatically, without using the web interface? I am using Plone3.1
I think (based upon a little grepping in buildout-cache/eggs/Zope2*) the importing process as triggered through the ZMI will end up calling
security.declareProtected(import_export_objects, 'manage_importObject')
def manage_importObject(self, file, REQUEST=None, set_owner=1):
"""Import an object from a file"""
from Zope2-*.egg/OFS/ObjectManager.py.
Copy your file MySite.zexp into the import folder of your plone instance (for Plone 3.1, it is probably located in ${PLONE_FOLDER}/parts/instance/import, or just look for the import folder using the find command). Then, use the following command line on the machine where the Zope server is running in order to import your zexp file into your ZODB:
$ wget http://admin:password#localhost:8080/manage_importObject?file=MySite.zexp
where admin and password are your admin user login and password respectively.