从Python启动脚本

时间:2018-02-21 16:27:54

标签: python cmd

我有你可以在下面看到的代码。我想先去目录,然后用管道“|”备份MongoDB的数据库。问题是,当我启动脚本时,控制台会返回我

  

mongodump不是内部或外部命令。

另一方面,如果我启动相同的行

cd C:\\...\\MongoDB\\Server\\3.6\\bin | mongodump -h ip -d database name -o C:\\Users\\...\\Desktop\\BackUpMongo

在我的系统cmd中没有问题。有什么想法吗?

import sys
import os

if __name__ == '__main__':

try:

    os.system('cd C:\\...\\MongoDB\\Server\\3.6\\bin | mongodump -h ip -d database name -o C:\\Users\\...\\Desktop\\BackUpMongo')


    print("Copia de seguridad finalizada")

except:
    print("Error during data base backup")


sys.exit(0)

1 个答案:

答案 0 :(得分:0)

使用//build the parameter expression of the object ParameterExpression parameter = Expression.Parameter(typeof(Foo), "x"); //the left member MemberExpression leftMember = Expression.Property(parameter, "Value1"); //the right member MemberExpression rightMember = Expression.Property(parameter, "Value2"); //and here I evaluate the boolean expression: Expression equalExpression = Expression.Equal(leftMember, rightMember); //the lambda of the equal expression LambdaExpression lambda = Expression.Lambda(equalExpression, parameter); //the object: Foo foo = new Foo { Value1 = 5, Value2 = 5 }; Delegate expression = lambda.Compile(); var eq = expression.DynamicInvoke(foo); 代替os.chdir()

os.system('cd ...')