Question: I have a problem with the ForeignKey, as you will see in the database table i have the following value "LA URBINA" in the column "EQU". in my model the property is:

```
[ForeignKey("Equipo")]
public string EQU { get; set; }

private Equipo equipo;
public virtual Equipo Equipo
{
    get { return equipo; }
    set { equipo = value; }
}

```

the problem is that in the table "Equipo" the key code is "La Urbina" not "LA URBINA" and therefore does not make the relationship, any idea to make the comparison regardless if the value is lower or upper? please excuse my bad English, I hope you understand me and you can help me

Answer: 
You could use Popen, checking stderr:

```
from subprocess import Popen,PIPE

proc = Popen(["EXEC"], stderr=PIPE,stdout=PIPE,universal_newlines=True)

out, err = proc.communicate()
if err:
    with open("std.err","w") as f:
        f.write(err)

```

On a side note, if you care about the return code you should use `check_call`, you could combine it with a `NamedTemporaryFile`:

```
from tempfile import NamedTemporaryFile
from os import stat,remove
from shutil import move

try:
    with NamedTemporaryFile(dir=".", delete=False) as err:
        subprocess.check_call(["exec"], stderr=err)
except (subprocess.CalledProcessError,OSError) as e:
    print(e)

if stat(err.name).st_size != 0:
    move(err.name,"std.err")
else:
    remove(err.name)

```
You can create your own context manager to handle the cleanup for you -- you can't really do what you're describing here, which boils down to asking how you can see into the future. Something like this (with better error handling, etc.):

```
import os
from contextlib import contextmanager

@contextmanager
def maybeFile(fileName):
   # open the file
   f = open(fileName, "w")
   # yield the file to be used by the block of code inside the with statement
   yield f
   # the block is over, do our cleanup.
   f.flush()
   # if nothing was written, remember that we need to delete the file.
   needsCleanup = f.tell() == 0
   f.close()
   if needsCleanup:
      os.remove(fileName)

```

...and then something like:

```
with maybeFile("myFileName.txt") as f:
   import random
   if random.random() < 0.5:
      f.write("There should be a file left behind!\n")

```

will either leave behind a file with a single line of text in it, or will leave nothing behind.