我一直在使用以下脚本来检查特定命名窗口是否已打开。
我从这个帖子中得到了它: -
How do you test if a window (by title) is already open from the command prompt?
理想情况下,如果发现它已打开,我会展开else部分以关闭窗口。
@For /f "Delims=:" %A in ('tasklist /v /fi "WINDOWTITLE eq test.bat - Notepad"') do @if %A==INFO (echo Prog not running) else SET "BREX=Awesome" &echo %BREX%
不幸的是,当我运行这个脚本时,它会返回我的其他字符串的三个实例?
有没有办法将其减少到返回一个实例?
答案 0 :(得分:1)
您可以使用# models
class Store(models.Model)
name = models.TextField()
class Stuff(models.Model)
store = models.ForeignKey(Store, related_name='stuffs')
first_name = models.TextField()
last_name = models.TextField()
# serializers
class StuffSerializer(serializers.ModelSerializer):
class Meta:
model = Stuff
fields = ('id', 'first_name', 'last_name', )
class StoreSerializer(serializers.ModelSerializer):
stuffs = StuffSerializer()
def create(self, validated_data):
instance = Stoer.objects.create(name=validated_data['name']
for stuff in validated_data['stuffs']
Stuff.objects.create(store=instance,
first_name=stuff['first_name'],
last_name=stuff['last_name'])
return instance
def update(self, instance, validated_data):
instance.name = validated_data['name']
instance.save()
for stuff in validated_data['stuffs']
stuff_instance = Stuff.objects.get(id=stuff['id'])
stuff_instance.first_name=stuff['first_name']
stuff_instance.last_name=stuff['last_name']
stuff_instance.save()
return instance
class Meta:
model = Store
fields = ('id', 'name', 'stuffs', )
# ModelViewSet
class StoreViewSet(viewsets.ModelViewSet):
queryset = Store.objects.all()
serializer_class = StoreSerializer
代替。当你在每行输出上循环时,你会得到多行输出
findstr
答案 1 :(得分:0)
如果你真的想通过cmd提示符中的一行执行此操作,则可以执行此操作。
var valueeee = 'NoneNoneNoneBP #15 Plain Felt 36" | $10.00NoneNoneNoneNoneNoneNone'
var strs = valueeee.replace(/\None/g,'');
var str = valueeee.replace(/\None|\|/g,'');
console.log(str);
console.log(strs);
或者使用一些条件执行。
cmd /v:on /c "@For /f "Delims=:" %A in ('tasklist /v /nh /fi "WINDOWTITLE eq test.bat - Notepad"') do @if %A==INFO (echo Prog not running) else (SET "BREX=Awesome") &echo !BREX!"