You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Now that you have created two arrays, can read and save them, and compare expected values.
Step 4
Use subprocess to call a system command from within python. The aim is for later to call Charlene's programme.
On a different python file (e.g., test_call_command.py) start with this content:
import subprocess
subprocess.run(["ls", "-aF"])
and run it!
Are you using Windows and getting errors?
If you're on Windows, ideally use Git Bash (If you're on the Windows Command Prompt cmd, you need to pass cmd-compatible commands to subprocess, e.g. dir instead of ls). On Windows, you might also need to pass shell=True as an additional argument.
subprocess.run(["ls", "-lh"], shell=True)
run it and iterate a couple of times changing the command that runs with others like:
ls -aF (which lists files),
echo 'hello world' (which prints hello world in the screen),
date +%Y%m%d (which prints today's date with the selected format)
wc -l sagittal_brain.py (which counts the number of lines of the sagittal_brain.py file)
wc -c AFileThatDoesNot.exist (which should counts the number of characters, but should fail as the file doesn't exist)
Once you've understood how subprocess.run works, try to call Charlene's programme.
Hint
How do you call a Python script from the command line? ______ filename.py.
React to this issue (#37) with a ❤ when your team has completed this task.
The text was updated successfully, but these errors were encountered:
Continuation from #36.
Now that you have created two arrays, can read and save them, and compare expected values.
Step 4
Use
subprocess
to call a system command from within python. The aim is for later to call Charlene's programme.On a different python file (e.g.,
test_call_command.py
) start with this content:and run it!
Are you using Windows and getting errors?
If you're on Windows, ideally use Git Bash (If you're on the Windows Command Prompt
cmd
, you need to passcmd
-compatible commands to subprocess, e.g.dir
instead ofls
). On Windows, you might also need to passshell=True
as an additional argument.run it and iterate a couple of times changing the command that runs with others like:
ls -aF
(which lists files),echo 'hello world'
(which prints hello world in the screen),date +%Y%m%d
(which prints today's date with the selected format)wc -l sagittal_brain.py
(which counts the number of lines of thesagittal_brain.py
file)wc -c AFileThatDoesNot.exist
(which should counts the number of characters, but should fail as the file doesn't exist)Once you've understood how
subprocess.run
works, try to call Charlene's programme.Hint
How do you call a Python script from the command line?
______ filename.py
.React to this issue (#37) with a ❤ when your team has completed this task.
The text was updated successfully, but these errors were encountered: