os.system执行时,子进程调用/ popen不起作用

时间:2017-11-05 21:08:50

标签: python

以下3行中只有最后一行有效:

subprocess.call(['rm', '-f', 'temp/*'])
subprocess.Popen(['rm', '-f', 'temp/*'])
os.system("rm -f temp/*")

对这种现象应该有一个自然的解释。

1 个答案:

答案 0 :(得分:0)

os.system通过bash调用命令,将temp/*之类的模式扩展为所有文件的列表。 subprocess.call将字符串temp/*直接提供给rm,该temp/*会尝试删除名为filenames = glob.glob('temp/*') subprocess.call(['rm', '-f'] + filenames) 的文件,该文件不存在。

如果您想拥有相同的行为,则必须自行扩展文件:

for (xx = 0; xx < bitmapInfoHeader.biWidth; xx++)
    {
        for (yy = 0; yy <bitmapInfoHeader.biHeight; yy++)
        {
            avgB = avgG = avgR = 0;
            Counter = 0;

            for (x = xx; x < bitmapInfoHeader.biWidth && x < xx + blurSize; x++)
            {


                for (y = yy; y < bitmapInfoHeader.biHeight && y < yy + blurSize; y++)
                {
                    avgB += bitmapImage[x *3 + y*bitmapInfoHeader.biWidth * 3 + 0];     //bitmapimage[x][y];
                    avgG += bitmapImage[x  *3 + y*bitmapInfoHeader.biWidth * 3 + 1];
                    avgR += bitmapImage[x *3 + y*bitmapInfoHeader.biWidth * 3 + 2];
                    Counter++;
                }
            }

            avgB = avgB / Counter;
            avgG = avgG / Counter;
            avgR = avgR / Counter;

            bitmapImage[xx * 3 + yy*bitmapInfoHeader.biWidth * 3 + 0] = avgB;
            bitmapImage[xx * 3 + yy*bitmapInfoHeader.biWidth * 3 + 1] = avgG;
            bitmapImage[xx * 3 + yy*bitmapInfoHeader.biWidth * 3 + 2] = avgR;
        }
    }
相关问题