I'm simply trying to break out of an R session when I've accidentally entered an incorrect command. Consider this captured text from the the R session:
json2["]
+ ""
+ "
Error: unexpected string constant in:
"""
""
I accidentally typed json["] and the R interpreter sees this as an incomplete command, and it then cycles me through the line continuation prompt, which is a plus '+" symbol, which is not what I want or need.
I then have to try and complete this invalid command to regain control of the console. What I want is a set of keystrokes to break out of this process, similar to a ctrl-c in a terminal session.
Related
Working with Fortran90 in Unix...
I have a programme which needs to read in the input parameters from a file "input-deck.par". This filename is currently hard-coded but I want to run a number of runs using different input-deck files (input-deck01.par, input-deck02.par, input-deck03.par etc.) so I've set-up the code to do a simple "read(*,*) inpfile" to allow the user to input the name of this file directly on run-time with a view to scripting this later.
This works fine interactively. If I execute the programme it asks for the file name, you type it in and the filename is accepted, the file is opened and the programme picks up the parameters from that file.
The issue lies in scripting this. I've tried scripting using the "<" pipe command so:
myprog.e < input-deck01.par
But I get an error saying:
Fortran runtime error: Cannot open file '----------------': No such file or directory
If I print the filename right after the input line, it prints that the filename is '----------------' (I initialise the variable as having 16 characters hence the 16 hyphens I think)
It seems like the "<" pipe is not passing the keyboard input in correctly. I've tried with spaces and quotes around the filename (various combinations) but the errors are the same.
Can anyone help?
(Please be gentle- this is my first post on SO and Fortran is not my primary language....)
Fortran has the ability to read the command line arguments. A simple example is
program foo
implicit none
character(len=80) name
logical available
integer fd
if (command_argument_count() == 1) then
call get_command_argument(1, name)
else
call usage
end if
inquire(file=name, exist=available)
if (.not. available) then
call usage
end if
open(newunit=fd, file=name, status='old')
! Read file
contains
subroutine usage
write(*,'(A)') 'Usage: foo filename'
write(*,'(A)') ' filename --> file containing input info'
stop
end subroutine usage
end program foo
Instead of piping the file into the executable you simply do
% foo input.txt
After upgrading to Perl 5.24.4 we repeatedly get this error in logs (without pointing the filename and line number):
Unable to flush stdout: Broken pipe
We have no idea what causes this error.
Is there any advice how to understand the cause of the error?
The error comes from perl.c, line 595:
PerlIO_printf(PerlIO_stderr(), "Unable to flush stdout: %s",
Strerror(errno));
This line is part of perl_destruct, which is called to shut down the perl interpreter at the end of the program.
As part of the global shutdown procedure, all still open filehandles are flushed (i.e. all buffered output is written out). The comment above says:
/* Need to flush since END blocks can produce output */
/* flush stdout separately, since we can identify it */
The error message is not listed in perldoc perldiag, which is arguably a documentation bug. It was probably overlooked because it's not a real warn or die call, it's effectively just print STDERR $message. It's not associated with a file name or line number because it only happens after your program stops running (i.e. after a call to exit or because execution fell off the end of the main script).
This is very general advice, but
use Carp::Always;
at the top of the script, or running with
perl -MCarp::Always the_script.pl arg1 arg2 ...
will get Perl to produce stack traces with every warning and error.
Broken pipe is the error string associated with system error EPIPE. One receives this error when writing to a closed pipe. Writing to a closed pipe usally results in the process being killed by a SIGPIPE, so it means the behaviour of SIGPIPE was changed from its default.
$ perl -e'
$SIG{PIPE} = "IGNORE";
print "foo\n"
or die("Can\x27t write to STDOUT: $!\n");
sleep(2);
close(STDOUT)
or die("Unable to flush STDOUT: $!\n");
' | perl -e'sleep(1)'
Unable to flush STDOUT: Broken pipe
As melpomene discovered, the error is automatically output if you write to a broken pipe in an END block.
$ perl -e'
$SIG{PIPE} = "IGNORE";
sleep(2);
END { print "foo\n"; }
' | perl -e'sleep(1)'
Unable to flush stdout: Broken pipe
This isn't necessarily a problem, although it could be a sign that a process is exiting prematurely.
I have a text file that contains some basic passwords and some variants of those basic passwords. They are typed out together like this:
qwerty, qwerty1
password, password1
default, default 1
123, 12345, 123456
I am trying to take these values and split them, storing them in a tuple and then print out the values as 'Password' and then any variants, but I am getting a syntax error on the print BIF? (I am aware this will not print out the password '123456', I am just trying to solve the syntax error first.)
for each_line in passwords:
(passwd, passwd_variant) = each_line.split(',',1)
print(f'Password: {passwd}, Variant {passwd_variant}')
SyntaxError: invalid syntax
normally if I was writing a script, in the editor I would put print on a new line, however a new line in IDLE simply executes the code above it. is there a shortcut or something to do a carriage return and write the print statement on a new line and if so, is that the cause of the syntax error and why?
Cheers
EDIT: I would like my output to be this
Finally discovered that you need to hit Enter after the for in statement, this will then take you to a new line inside for in statement. Was up all night trying to work it out, maybe my fresh brain helped this morning.
Recently I have been trying to use R to call a .exe program named mGenov It's command line program. I have some screenshots to help me explain this (I use Windows 10).
Supposedly, it works this way:
double click on mGenova,
type card.txt
hit "enter" the cmd window will close
I have tried a lot; basically they can invoke the program, but pass the command about typing card.txt in the command
shell(cmd="D:\\mgenova\\mGENOVA\\card.txt", shell="D:\\mgenova\\mGENOVA\\mGENOVA.exe",intern=F)
OR
system("\"D:\\mgenova\\mGENOVA\\mGENOVA.exe\" \"D:\\mgenova\\mGENOVA\\card.txt\""
,show.output.on.console=TRUE,invisible=T,intern=T)
And I always got this
[1] "Input the filename containing the control cards." "" "" "*** Control cards file is empty"
attr(,"status")
[1] 1
Warning message:
running command '"D:\mgenova\mGENOVA\mGENOVA.exe" "D:\mgenova\mGENOVA\card.txt"' had status 1
How can I get it run on it? Thanks for helping!!!!!
You could create a batchfile (let's name it batch.bat) on Windows with the content
cd /D D:\mgenova\mGENOVA\
mGENOVA.exe < card.txt
All necessary input for GENOVA must be provided by the file card.txt.
Then in R run the command
system("batch.bat")
Here is a basic script with getopt command and assigned variables.
If someone were to type in
MyScript -a
with no words or numbers added after the -a, then an error message would pop up! The same happens if you replace -a with any other assigned variables. If I wanted no error message to appear, how would I go about doing this?
Hints/advice is preferred over a simply strict answer!
From the bash manual:
getopts can report errors in two ways. If the first character of optstring is a colon, silent error reporting is used. In normal operation diagnostic messages are printed when invalid options or missing option arguments are encountered. If the variable OPTERR is set to 0, no error messages will be displayed, even if the first character of optstring is not a colon.
Since you tag the question with Unix and don't mention bash, you may or may not be so lucky, but the answer is to read the manual page carefully.