2

Good morning,
I am writing a Python script for comparing two installers. Therefore I am using "sfk" (Swiss File Knife) technology for browsing through the unzipped directories, including browsing inside *.jar files).
My script looks as follows:

  cmd_sfk1 = "sfk list -hidden -arc -time -size -tofile content_dir1.txt " + lv_inst_dir1
  cmd_sfk2 = "sfk list -hidden -arc -time -size -tofile content_dir2.txt " + lv_inst_dir2

  try:
    subprocess.call(cmd_sfk1)
  except Exception as ex:
    ...

  try:
    subprocess.call(cmd_sfk2)
  except Exception as ex:
    ...

As you can see, the results are written in two files (content_dir1.txt) and (content_dir2.txt), and it's the idea that a simple file comparison gives me the difference between both directories/file tree.

However, this is not working as the name of the directory is included in the file, here's an excerpt:

...
2015-09-29 14:04:20          119 Dir1\InstallerData\...\MediaId.properties
2015-09-29 14:00:08          357 Dir1\InstallerData\...\\my.ini
...

The presence of "Dir1" in that file messes up the comparison.

I see one "simple" solution: modifying the target directory of the commands, something like:

  cmd_sfk1 = "sfk list -hidden -arc -time -size -tofile ../content_dir1.txt " + "."
  cmd_sfk2 = "sfk list -hidden -arc -time -size -tofile ../content_dir2.txt " + "."

  try:
    subprocess.call(cmd_sfk1, target_directory=lv_inst_dir1)
  except Exception as ex:
    ...

  try:
    subprocess.call(cmd_sfk2, target_directory=lv_inst_dir2)
  except Exception as ex:
    ...

(a bit like "pushd" and "popd" in DOS batch-files)
The intention is to end up with following content_dir1.txt content:

...
2015-09-29 14:04:20          119 InstallerData\...\MediaId.properties
2015-09-29 14:00:08          357 InstallerData\...\\my.ini
...

(without "Dir1")
And now my question: does anybody know how to modify the target directory of a subprocess in Python?

Thanks
Dominique

1 Answer 1

2

The argument is cwd

subprocess.call(cmd_sfk1, cwd=lv_inst_dir1)

subprocess.Popen

Sign up to request clarification or add additional context in comments.

1 Comment

It seems that "cwd" stands for "Current Working Directory".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.