scripting

Using Powershell, how can i count the occurrence of each element in an array?

半腔热情 提交于 2019-12-29 06:10:07
问题 If I have an array: 1 1 1 2 2 3 4 4 4 4 5 5 How can I use Powershell to tell me how many of each element there are in that array? To be a little more clear, I should have a separate count for each array element: Element:Count 1:3 2:2 3:1 4:4 5:2 回答1: You can use the Group-Object cmdlet: PS> 1,1,1,2,2,3,4,4,4,4,5,5 | group Count Name Group ----- ---- ----- 3 1 {1, 1, 1} 2 2 {2, 2} 1 3 {3} 4 4 {4, 4, 4, 4} 2 5 {5, 5} If you want a hashtable for the items and their counts you just need a little

How to return spawned process exit code in Expect script?

荒凉一梦 提交于 2019-12-29 05:46:48
问题 I use expect for running test scripts. Tests return success/failure through exit code. But expect return equivalent exit code. How to make expect return proper exit status? My tests are sql scripts run with psql (postgresql command processor). Since psql doesn't allow to specify database password as a command line parameter, expect scripts do that. So, my expect script looks like: spawn $SPAWN_CMD expect { -re "Enter password for new role:" { send "$PWPROMPT\n" exp_continue } -re "Enter it

Can a python script persistently change a Windows environment variable? (elegantly)

亡梦爱人 提交于 2019-12-29 05:23:47
问题 Following on from my previous question, is it possible to make a Python script which persistently changes a Windows environment variable? Changes to os.environ do not persist once the python interpreter terminates. If I were scripting this on UNIX, I might do something like: set foo=`myscript.py` But alas, cmd.exe does not have anything that works like sh's back-tick behavior. I have seen a very long-winded solution... it 'aint pretty so surely we can improve on this: for /f "tokens=1* delims

Converting RAW audio data to WAV with scripting

拜拜、爱过 提交于 2019-12-29 05:07:06
问题 I have a large number of .RAW audio files (unsigned 8-bit PCM with no-endianness) which I want to convert to .WAV files. What command-line tool (windows or linux) can I use to convert these quickly? 回答1: I was pointed to SoX by a friend, which did the trick. The syntax used was sox -r 44100 -e unsigned -b 8 -c 1 <RAW_FILE> <TARGET_FILE> 回答2: I found sox to be incredibly fast and reliable. I use it for a dictation solution I put together with Asterisk. If you are using sox though, be aware

How to get a script in init.d to execute on boot in Android?

大兔子大兔子 提交于 2019-12-29 04:56:36
问题 Part of my android app's functionality it to place a script I have written in init.d, so that it will be executed on every startup. (obviously my app is for root users only) Here's what I am doing: busybox mount -o rw,remount /system" busybox cp -f /sdcard/*******/script /system/etc/init.d/script busybox chmod +x /etc/init.d/script update-rc.d script 99 The "update-rc.d script 99" line is where I run into trouble, it fails with an "update-rc.d not found" error. Does anyone know what the

Override a variable in a Bash script from the command line

有些话、适合烂在心里 提交于 2019-12-29 02:51:07
问题 How do you override a variable in your Bash script from the command line? I know how to pass variables in, but I just want something like ./myscript.sh -Dvar=val . 回答1: You need to use parameter expansion for the variable(s) you want to override: $ cat override.sh #!/bin/bash : ${var1:=foo} # var1 will take on the value "foo" if not overridden var2=${var2:-foo} # same thing but more typing echo "var1 is $var1 | var2 is $var2" Without Override Values $ ./override.sh var1 is foo | var2 is foo

Programmatically generate script for all objects in a database

笑着哭i 提交于 2019-12-28 18:49:31
问题 For an automated setup build that generates the setup for an application which uses Microsoft SQL Server, I am currently evaluating whether the following is possible: I want to programmatically (CMD script or C# code) execute the function "Generate Scripts" on a database that is accessible from Microsoft SQL Server Management Studio 2008. I.e. call some code and have all the objects (tables, SPs, constraints, etc.) of a specified database as an SQL script. Currently, I only need the structure

C# Scripting language

梦想的初衷 提交于 2019-12-28 11:55:31
问题 This is a somewhat odd question. I want to provide a scripting language for modding games that I build for XNA. If I was deplying these games for the PC then I would just be able to use C# files, compiled at runtime (Using reflection.emit) as scripts and that would be fine - a nice simple way to mod the game. However, the .net compact framework (which is what the xbox provides) does not support reflection.emit, so how can I write a scripting language taking this into account? Are there any

Embedding a Ruby interpreter in a C++ app

你说的曾经没有我的故事 提交于 2019-12-28 11:46:08
问题 I'm hoping to use Ruby as a scripting language for my game engine. I've found the usual articles describing how to call Ruby classes from C++ code and vice versa (e.g. here) but I can't quite see how to do what I want with that way of working... My engine currently uses a little language I wrote myself with Flex and Bison, and a little stack based virtual machine. Scripts don't always run right through from start to finish, for instance they sometimes includes commands like "sleep for 2

total size of group of files selected with 'find'

一个人想着一个人 提交于 2019-12-28 08:07:23
问题 For instance, I have a large filesystem that is filling up faster than I expected. So I look for what's being added: find /rapidly_shrinking_drive/ -type f -mtime -1 -ls | less And I find, well, lots of stuff. Thousands of files of six-seven types. I can single out a type and count them: find /rapidly_shrinking_drive/ -name "*offender1*" -mtime -1 -ls | wc -l but what I'd really like is to be able to get the total size on disk of these files: find /rapidly_shrinking_drive/ -name "*offender1*"