1. Which command will print out the exit value of a script that just ran successfully?
Answers
·
wc variables.py
·
echo $?
· echo $PATH
· import sys
Explanation: The $? variable in
Bash stores the exit status of the execution of the most recent command. It is
possible to print out the exit value of the script or command that was
currently being performed by using the echo $? command. With a successful
execution of the script, the exit value will normally be 0.
2. Which command will
create a new environment variable?
Answers
·
export
·
env
· input
· wc
Explanation: To generate or edit
environment variables in Bash, the export command is the tool to utilize. You
might use the following command, for instance, in order to create a new
environment variable with the name MY_VARIABLE and a value of 123:For the
purpose of making the MY_VARIABLE environment variable accessible to other
processes and commands running inside the same shell session, this command
first creates the variable and then sets it to the value 123.
3. Which I/O stream are
we using when we use the input function to accept user input in a Python
script?
Answers
·
STDOUT
·
STDERR
· STDIN
· SYS
Explanation: When we use the
input() method in Python to receive input from the user, we are reading data
from the standard input stream, often known as STDIN. During the course of the
program's execution, the user is able to directly enter data, thanks to this
function.
4. What is the meaning of an exit code of 0?
Answers
·
The program ended with an unspecified
error.
·
The program ended with a ValueError.
· The program ended with a TypeError.
· The program ended successfully.
Explanation: In a wide variety
of programming languages and operating systems, including some that are similar
to Unix, an exit code of 0 normally indicates that the program executed
correctly and did not experience any issues during its termination. It is
common practice to use the value 0 as the exit code to indicate that the
execution was successful. When a program finishes its execution with a status
code of 0, it indicates that it has successfully finished its work without any
problems or deviations from the intended results.
5. Which statements are
true about input and raw_input in Python 2? (select all that apply)
Answers
·
input performs basic math
operations.
·
raw_input performs basic math
operations.
· raw_input gets a string from the user.
· input gets a string from the user.
6. What type of object
does a run function return?
Answers
·
returncode
·
capture_output
· stdout
· CompletedProcess
Explanation: After the
conclusion of the process, the run() method in the subprocess module of Python
produces a CompletedProcess object. There is information about the process that
was executed included inside this object. This information includes the
process's return code, standard output, and standard error. This enables the
program that is invoking the subprocess to examine and manage the outcomes of
the execution of the subprocess.
7. How can you change
the current working directory where a command will be executed?
Answers
·
Use the capture_output parameter.
·
Use the cwd parameter.
· Use the shell parameter.
· Use the env parameter.
Explanation: You are able to
alter the current working directory in which a command will be performed by
using the cwd argument in the subprocess module of Python. This allows you to
modify the directory in which the command will be executed. Through the use of
this option, you will have the ability to determine the working directory for
the subprocess before it actually runs the command.
8. When a child process
is run using the subprocess module, which of the following are true? (check all
that apply)
Answers
·
The child process is run
in a secondary environment.
·
The parent process is
blocked while the child process finishes.
· The parent process and child process both run simultaneously.
· Control is returned to the parent process when the child process ends.
9. When using the run
command of the subprocess module, what parameter, when set to True, allows us
to store the output of a system command?
Answers
·
cwd
·
capture_output
· timeout
· shell
Explanation: By using the run()
method of the subprocess module in Python and setting the capture_output option
to True, we are able to record the output of a system command, which includes
both the standard output and the standard error. After that, the stdout and stderr
elements of the CompletedProcess object that was returned may be used to view
this output.
10. What does the copy
method of os.environ do?
Answers
·
Creates a new dictionary
of environment variables
·
Runs a second instance of an
environment
· Joins two strings
· Removes a file from a directory
Explanation: It is possible to
generate a shallow copy of the dictionary that contains the environment
variables by using the copy method of the os.environ class. It does not delete
a file from a directory, nor does it create a new instance of the environment,
nor does it connect two strings, nor does it join two strings together.
Instead, it gives you the ability to make changes to the cloned dictionary
without having an effect on the variables that were associated with the
original environment.