Now that you have created two arrays, can read and save them, and compare expected values.
Step 4
[!CAUTION]
If you are using Windows, it will be easier to run the following from Git Bash (otherwise read the following information)
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.
```python
subprocess.run(["ls", "-lh"], shell=True)
```
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!
Once it produces the expected output, 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 (#25) with a ❤ when your team has completed this task.
Continuation from #24.
Now that you have created two arrays, can read and save them, and compare expected values.
Step 4
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. ```python subprocess.run(["ls", "-lh"], shell=True) ```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!
Once it produces the expected output, 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 (#25) with a ❤ when your team has completed this task.