How to pass terminal errors into Python script? - python

How to Pass a Terminal error into the Python program whenever the error is triggered in the terminal?
Example:
Consider I'm running a java program and I get some error like this
file.java:2: error: ',', ')', or '[' expected
public static void main(String args...) {
^
1 error
Another example by entering the wrong bash command
ls: option '--a' is ambiguous; possibilities: '--all' '--almost-all' '--author'
Try 'ls --help' for more information.
I need to pass this error to a python program and run the program whenever the terminal shows the error like this.
How can I pass the error?

Related

Certutil "Too Many Arguments" error when using python os.system command window

Trying to decode a simple file into a temporary text file using the code below:
os.system("start cmd /k certutil -f -decode \\SDHQFILE03.enxco.com\\arcgis\\General\\Solar\\R_and_D\\CodeLibrary\\Python\\EPE2.1.7\\34287.bat \\SDHQFILE03.enxco.com\\arcgis\\General\\Solar\\R_and_D\\CodeLibrary\\Python\\SETI\test3.txt")
Everytime I run this I get an error from certutil that I have too many arguments (3 with 2 expected) - copying the code directly into the command window as shown it runs correctly:
certutil -f -decode \\SDHQFILE03.enxco.com\\arcgis\\General\\Solar\\R_and_D\\CodeLibrary\\Python\\EPE2.1.7\\34287.bat \\SDHQFILE03.enxco.com\\arcgis\\General\\Solar\\R_and_D\\CodeLibrary\\Python\\SETI\test3.txt
What am I missing on the first statement to allow it to run without error?

Laravel: The command "python failed. Exit Code: 1(General error) 'python' is not recognized as an internal or external command, operable

I try to run Python script in the Laravel. I am using composer require symfony/process for this. Actually I don't want to use shell_exec(). But when I try to run it returns me error. In the command line everything is okay. My python script located in public folder. Can someone help to solve this issue?
My Controller:
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;
$process = new Process(['python', 'C:/Users/User/Desktop/www/abyss-hub/public/hello.py']);
$process->run();
// executes after the command finishes
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}
return $process->getOutput();
Python script:
print('Hello Python')
OUTPUT:
The command "python "C:/Users/User/Desktop/www/abyss-hub/public/hello.py"" failed. Exit Code: 1(General error) Working directory: C:\Users\User\Desktop\www\abyss-hub\public Output: ================ Error Output: ================ 'python' is not recognized as an internal or external command, operable program or batch file.

Can't see output, only in terminal

I'm trying to write some Go code in VScode.
I have the Code Runner (v. 0.9.9) and Go (v 0.10.2) extensions.
I tried to run the following:
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
In the output tab I got:
[Running] go run "/home/joe/code/test.go"
[Done] exited with code=0 in 0.236 seconds
Which does not include the output of the Println statement. While if I run it from terminal (from VScode even), I get:
joe#HP-Laptop-15-bs0xx:~/code$ go run test.go
Hello, World!
This, by the way, repeats itself with other languages I've tried as well (like Python).
How can I fix this so I can get the actual output to the output tab?
For output tab only execute go test without verbose command. you must be add -v argument to go test config.
Add this to settings.json on VSCODE
"go.testFlags": ["-v"],

Executing Python commands in Jupyter notebook with prompts

When the function below is entered into a notebook cell, the output will have an input box to enter the details of the prompt.
def a():
val = raw_input("abc")
print "Entered value: %s" % val
I'm trying to achieve the same thing by running the script, but it doesn't work. I've copied the same code for the function above into a script sample.py as below.
# cat sample.py
def a():
val = raw_input("abc")
print "Entered value: %s" % val
a()
Attempts to achieve the same behavior of getting a notebook prompt while running the script from notebook:
1. Using the '!' prefix
This command just keeps running without giving any prompt:
[*] !python sample.py
abc
2. Using %%bash
Gives the following error:
%%bash
python sample.py
EOFError: EOF when reading a line
What is the reason for this to fail and is there a workaround to get it working as expected?
The two command you've used are used for shell command and bash script respectively.
To run Python script as a program you can use Magic command run.

$ Error running an executable from SQLPLUS

I have created this executable out of a python script. All it does is prints 'Hello World'. I am trying to run this off SQLPlus.
My SQlPlus query is as provided below:
START 'C:\USERS\ADMINISTRATOR\DESKTOP\dist\HW.exe'
I keep getting the following error:
Using 'Host', gives:
Any help/suggestion/edits would be appreciated.
I have also plainly tried to run the python script 'HW.py' resulting in the following error:
What is the right way to execute the HW.exe from SQLPlus?

Categories

Resources