Permission denied error while running a code on google cloud ML - google-cloud-ml

I am getting an error while trying to read a file within the code.
File isn't open for reading") PermissionDeniedError: File isn't open for reading
file is located within the trainer folder on the google cloud shell. This is what I have given to read the file with file_io.FileIO('/home/arpit_agrawal/DeepSpeech/trainer/data/‌​spell/words.txt','r+‌​') as f: WORDS = set(words(f.read()))
THIS WAS THE ERROR IN LOG FILES : WORDS = set(words(f.read())) File "/root/.local/lib/python2.7/site-packages/tensorflow/python/‌​lib/io/file_io.py", line 106, in read self._preread_check() File "/root/.local/lib/python2.7/site-packages/tensorflow/python/‌​lib/io/file_io.py", line 70, in _preread_check "File isn't open for reading") PermissionDeniedError: File isn't open for reading
result of ls -la for words.txt
-rwxr-xr-x 1 arpit_agrawal arpit_agrawal 12124743 Apr 11 17:53 words.txt

It looks like it is a unicode issue in the code you pasted. Specifically there are non printable unicode characters there. I copied and pasted from the code you wrote and ran the following.
In [2]: 'r+‌​'=='r+'
Out[2]: False
The left one was copied from the original stackoverflow post. I'd suggest deleting that code and retyping it.

Related

Multiple failed attempts to open a text file in C++

I have been spending the past hour trying to figure out how to display a text document programmatically in c++.
The following is the simple main.cpp code, in which I create a directory "Profiles", and another directory "TestProfile" inside. In Profiles/TestProfile I create a "TestFile" and write "Test data" into it.
#include <iostream>
#include <fstream>
#include <sys/stat.h>
#include "Profile.hpp"
#include <stdlib.h>
using namespace std;
int main(int argc, const char * argv[]) {
ofstream fs;
mkdir("/Users/dario/Desktop/Profiles", S_IRWXU);
mkdir("/Users/dario/Desktop/Profiles/TestProfile", S_IRWXU);
fs.open("/Users/dario/Desktop/Profiles/TestProfile/TestFile");
fs << "Test data\n";
string path = "/Users/dario/Desktop/Profiles/TestProfile/TestFile";
system(path.c_str());
return 0;
}
Everything up until line 30 works as expected. The directories are there, and "TestFile" is present with data written.
There are no errors present when compiling, but ./a.out gives me a permission denied
darios-mbp:FMES dario$ g++ -std=c++2a main.cpp
darios-mbp:FMES dario$ ./a.out
sh: /Users/dario/Desktop/Profiles/TestProfile/TestFile: Permission denied
I tried a few approaches.
First, I checked the permissions of the text file using ls -l,
it returned -rw-r--r--, so I used chmod 755. After that, the file permissions said -rwxr-xr-x. When running the same code, ./a.out returned no permission denied and it seems like it worked, but the text file was not opened.
Secondly, after the first approach didn't work, I deleted the directories and ./a.out to recreate the original permission denied issue.
I was getting permission denied as before, and this time I tried changing the ownership or the directory.
sh: /Users/dario/Desktop/Profiles/TestProfile/TestFile: Permission denied
darios-mbp:FMES dario$ chown -R $USER
/Users/dario/Desktop/Profiles/TestProfile/TestFile
darios-mbp:
The command worked, but running the code still did nothing despite no errors.
I tried chmod 755, but again no file was opened.
On previous attempts to fix this issue, after changing the ownership the same way I just explained, I even had an error where it was trying to run the first word of the textfile as a command
Line 1: Test: command not found
Although I was not able to recreate that while writing this.
Perhaps I am doing something completely wrong, but I looked as much as I could for solutions online before writing this post. None of them seemed to work. Perhaps my situation is unique in some way and someone here could help point me in the right direction. I apologize in advance if my post is in any way not to standard (if so, please let me know how I can improve questions for next time).h
I am running the code on xcode
EDIT
Thanks to #Codo for the answer, the following edit did what I was looking for
string path = "/Users/dario/Desktop/Profiles/TestProfile/TestFile";
string cmd = "open -a TextEdit ";
system(cmd.c_str());
I understand that you want to open the created file with an appropriate application. Let's assume the file is /dir/file.
To open a file from the command line / terminal, you would run:
open /dir/file
Or, if you want a specific applications:
open -a TextEdit /dir/file
Also see The macOS open Command.
If you just run:
/dir/file
you would execute the file. That's probably not what you intended. And execution is only possible if the file meets certain criteria like execution rights and in the case of a shell script an appropriate header.
In C++, the system() function executes a command that would be valid on the command line (in the terminal).
Thus, to fix your program, change the line with system() to:
string cmd = "open -a TextEdit ";
cmd += path;
system(cmd.c_str());
And for your next question: Paste code as text, not as image: Why not upload images of code/errors when asking a question?

rmarkdown error: "myfile.tex"' had status 1

I am trying to compile an RMarkdown document from an R script. This is the code I am running:
setwd("C:/Users/me/me_VN02_5676/myfolder")
rmarkdown::render("myrmd.Rmd",
output_file = "mypdf.pdf")
This results in the error:
Error: Failed to compile mypdf.tex.
In addition: Warning message:
running command '"pdflatex" -halt-on-error -interaction=batchmode "mypdf.tex"' had status 1
Does anyone know what is happening?
Additional Notes
The PDF file is created when I use the Knit button in RStudio
This code does produce the .Tex file and when I run that it produces the pdf but render() does not produce the pdf
When I run the .R file via the command line it works! The PDF is created but why doesn't it work in R studio?
It would help to provide a Minimal Working Example so that we can attempt to replicate the problem. However, there may be two potential causes:
File Paths Look Incorrect
In R, they should be specified with a single forward slash: https://stat.ethz.ch/R-manual/R-devel/library/base/html/file.path.html
setwd("C:/Users/me/me_VN02_5676/myfolder")
rmarkdown::render("myrmd.Rmd",
output_file = paste0("mypdf.pdf")
)
PDF Output File May be Open
Another potential cause of this is that the PDF file is open, and therefore pandoc cannot save the output PDF. Try closing the PDF and render the document again.
Link to previous issue in Knitr which relates to this: https://github.com/yihui/knitr/issues/1209

Ubuntu shell script: Using >> the output txt file is not opening

I using the following python script to create a shell script:
with open("decode_JOURNAL2017.sh", "a") as myfile:
levels_no = 16
#myfile.write("#!/bin/bash\n")
for x in range(0, levels_no):
myfile.write("/home/zinonas/SHM-12.3/bin/TAppDecoderStatic -b /home/zinonas/str/pirkagia_10b_lowdelay_P.bin -olsidx "+str(x)+" -o"+str(x)+" /home/zinonas/decode/pirkagia_10b_lowdelay_P_level_"+str(x)+"_dec.yuv >> /home/zinonas/decode/pirkagia_10b_lowdelay_P_level_"+str(x)+"_dec.txt\n")
Then I transfer the following created script to an ubuntu server:
/home/zinonas/SHM-12.3/bin/TAppDecoderStatic -b /home/zinonas/str/pirkagia_10b_lowdelay_P.bin -olsidx 0 -o0 /home/zinonas/decode/pirkagia_10b_lowdelay_P_level_0_dec.yuv >> /home/zinonas/decode/pirkagia_10b_lowdelay_P_level_0_dec.txt
/home/zinonas/SHM-12.3/bin/TAppDecoderStatic -b /home/zinonas/str/pirkagia_10b_lowdelay_P.bin -olsidx 1 -o1 /home/zinonas/decode/pirkagia_10b_lowdelay_P_level_1_dec.yuv >> /home/zinonas/decode/pirkagia_10b_lowdelay_P_level_1_dec.txt
/home/zinonas/SHM-12.3/bin/TAppDecoderStatic -b /home/zinonas/str/pirkagia_10b_lowdelay_P.bin -olsidx 2 -o2 /home/zinonas/decode/pirkagia_10b_lowdelay_P_level_2_dec.yuv >> /home/zinonas/decode/pirkagia_10b_lowdelay_P_level_2_dec.txt
When I run it, the txt files are created but when I double click to one to open it I get this message:
Can't create file 'C:\Users\admin\AppData\Local\Temp\scp43940\home\zinonas\decode\pirkagia_10b_lowdelay_P_level_0_dec.txt
'.
System Error. Code: 123.
The filename, directory name, or volume label syntax is incorrect
I can't even transfer this txt file to my windows desktop via winscp.
The yuv files are working properly!
EDIT: When I copy/paste the content of the shell script to the terminal, the txt files are working properly.
EDIT 2: When I rename the file and remove txt and add it again, the file opens properly...
Do you know how to fix this?
Thank you in advance!
You probably have Windows line endings in the script file – at least that's why I get from the error message if you pasted it correctly.
Run dos2unix scriptFilename.sh or sed -i 's/\r//' scriptFilename.sh to remove the Windows line endings from the script.
For Python scripting refer to this Question&Answer: How to write Unix end of line characters in Windows using Python
I found the solution.
While creating the shell script, next to the name of the txt file I had:
...
>> /home/zinonas/decode/pirkagia_10b_lowdelay_P_level_"+str(x)+"_dec.txt\n")
so the new line character \n want next to txt. That was the problem. I added a new space between them and the problem solved!
My new code now reads:
...
>> /home/zinonas/decode/pirkagia_10b_lowdelay_P_level_"+str(x)+"_dec.txt \n")
Is there a "rogue" CR at the end of the file name?

open() - Fortran runtime error: File '' does not exist when exe ran with Python / Bottle

I have a Fortran exe that is being moved on to an IaaS. The Fortan exe runs fine when run from console (Windows), but when I call the exe from Bottle RESTserver (locally) the file paths do not work and the I get the following error:
At line 79 of file MainCalculator.f90 (unit = 61, file = '└')
Fortran runtime error: File '' does not exist
Here is my Python / Bottle code to execute the Fortran:
def model():
curr_dir = os.path.dirname(os.path.realpath(__file__))
exe = "Calculator.exe"
path = os.path.join(curr_dir, 'bin', 'fortan_model', 'Debug', exe)
a = subprocess.Popen(path, shell=False)
a.wait()
Here is the line of code that throws the error in Fortran:
open(UNIT=61, FILE=trim(adjustl(recipePath))//"Scenarios.txt")
where, recipePath = '..\..\ourRecipes\OUR_recipes_082014\' (defined in another .f90 file)
It seems the file path is being reported as an ASCII value (file = '└'), which does not happen when the exe is run from command line. I thought it maybe the relative paths, but it gives the same error with absolute paths, but with file = '≡f*☺└'.
It also creates a file name ' Scenarios.txt' (with spaces in front).
EDIT: The Fortran .exe reads an input txt file. Each row is assigned to a variable. This works as intended from the command line, but when executed from Bottle, it parses the input file as blank characters. Do I need to grant Python permission to read the file and/or open the input file in memory?
I had a similar problem.
I solved this problem by decreasing the size of the output file name.

Why this sublimetext build file dont work?

I am trying to capture the output of the build, for open the file with the syntax error.
This is the build file:
{
"cmd": ["D:\\xampp\\apache\\conf\\buildApache.bat"],
"file_regex": "of (.*?)(?=:)",
"line_regex": "line ([0-9]*) ",
"selector":"source.apacheconf"
}
This is the response from the build File
AH00526: Syntax error on line 19 of D:/xampp/apache/conf/extra/httpd-vhosts.conf:
Invalid command 'Liste', perhaps misspelled or defined by a module not included in the server configuration
[Finished in 0.3s]
What I am trying to do, is when the user, dbl-click on the error, it's will open the file, on line 19.
How Do I write the build file?
In SublimeText 2, The source code file name must appear BEFORE the line number in the build output.
That way, It's impossible to capture the output.