scripting

Setting the global LUA_PATH variable from C++/C?

こ雲淡風輕ζ 提交于 2019-12-18 11:13:14
问题 I'm trying to set my global LUA_PATH variable directly from C/C++, I'm using Lua from my iPhone applications, so my path tends does change between applications ( each iPhone app has a separate folder in the device ). I know I could set the LUA_PATH by recompiling lua with a "fixed" path, but that's quite far from ideal. ( I'm trying to do this in order to be able to use require , from my .lua scripts. Could anyone help me out here ? 回答1: In C++: int setLuaPath( lua_State* L, const char* path

mongo shell script won't let me include “use <database>”

不打扰是莪最后的温柔 提交于 2019-12-18 11:01:44
问题 32-bit mongo 2.0.1 on a windows XP machine //script filename: test.js (one line shell script file to store a person) db.cTest.save({Name: "Fred", Age:21}); run against database dbTest by entering the following 2 shell commands: > use dbTest switched to dbTest > load("test.js") So far, so good. But if I try and include the "use" statement in the script it fails: //script filename: test.js (including "use" statement) use dbTest; db.cTest.save({Name: "Fred", Age:21}); fails with error msg as

Looping through directories in Bash

时间秒杀一切 提交于 2019-12-18 10:46:14
问题 I require the script to cd to a directory, then delete all but a few files in sub-directories—but leave the folders alone. Would it help to use switch / case s for each file I need to preserve? Ideally, I think it should keep searching for further sub-dirs, instead of me having nested loops which only search down two levels. Another problem is that it skips folders with spaces (though this isn’t an issue with the volumes that the script will run, for now). Here’s my code: for i in /Users

Get list of variables whose name matches a certain pattern

流过昼夜 提交于 2019-12-18 10:39:37
问题 In bash echo ${!X*} will print all the names of the variables whose name starts with 'X'. Is it possible to get the same with an arbitrary pattern, e.g. get all the names of the variables whose name contains an 'X' in any position? 回答1: Use the builtin command compgen: compgen -A variable | grep X 回答2: This should do it: env | grep ".*X.*" Edit: sorry, that looks for X in the value too. This version only looks for X in the var name env | awk -F "=" '{print $1}' | grep ".*X.*" As Paul points

Changing IIS6 Site Home Directory with Powershell

天大地大妈咪最大 提交于 2019-12-18 10:36:27
问题 I'm trying to change a site's home directory using powershell. This is what I have so far, but it isn't saving the changes... $server = "localhost" $siteName = "mysite" $iis = [ADSI]"IIS://$server/W3SVC" $site = $iis.psbase.children | where { $_.keyType -eq "IIsWebServer" -AND $_.ServerComment -eq $siteName } $path = [adsi]($site.psbase.path+"/ROOT") $path.path = "D:\Sites\mysite\www2" $site.psbase.CommitChanges() 回答1: $server = "localhost" $siteName = "mysite" $iis = [ADSI]"IIS://$server

git: a quick command to go to root of the working tree

廉价感情. 提交于 2019-12-18 10:32:58
问题 I wanted a simple git command to go up to the "root" of the repository. I started with a script, but figured that I cannot change active directory of the shell, I had to do a function. Unfortunately, I cannot call it directly with the non-dash form "git root", for instance. function git-root() { if [ -d .git ]; then return 0 fi A=.. while ! [ -d $A/.git ]; do A="$A/.." done cd $A } Do you have a better solution? (the function has been written quickly, suggestions are welcome) 回答1: This has

convert binary data to hex in shell script?

試著忘記壹切 提交于 2019-12-18 10:32:33
问题 feel a bit stupid asking this (sounds as basics) but can't find an answer elsewhere. I want to convert binary data to hex, just that, no fancy formatting and all. hexdump seems too clever, it "overformats" for me. I want to take x bytes from the /dev/random and pass them on as hex. Preferably I'd like to use only standard linux tools, so that I don't need to install it on every machine (there are many) 回答1: Perhaps use xxd : % xxd -l 16 -p /dev/random 193f6c54814f0576bc27d51ab39081dc 回答2:

How to check if memcache or memcached is installed for PHP?

假装没事ソ 提交于 2019-12-18 10:26:39
问题 How do I test if memcache or memcached (for PHP) is installed on my Apache webserver? Memcache is a caching daemon designed especially for dynamic web applications to decrease database load by storing objects in memory. 回答1: You can look at phpinfo() or check if any of the functions of memcache is available. Ultimately, check whether the Memcache class exists or not. e.g. if(class_exists('Memcache')){ // Memcache is enabled. } 回答2: why not use the extension_loaded() function? 回答3: Use this

How to Pass parameters for a Ant script , which is invoked via shell script?

旧城冷巷雨未停 提交于 2019-12-18 10:22:39
问题 I need to invoke a ant script via shell script. Let us consider the parameters for ant script are a,b,c. how can i pass the parameter for those variables? I must provide the parameters for ant vis invoke the shell script. can anyone help me on this? 回答1: Do you mean assigning value to a property from command line? If so, try -DpropertyName=itsValue For example, <project> <target name="hi"> <property name="person" value="world"/> <echo message="Hello ${person}"/> </target> </project> and then

How to get the Parent's parent directory in Powershell?

浪尽此生 提交于 2019-12-18 10:19:24
问题 So if I have a directory stored in a variable, say: $scriptPath = (Get-ScriptDirectory); Now I would like to find the directory two parent levels up. I need a nice way of doing: $parentPath = Split-Path -parent $scriptPath $rootPath = Split-Path -parent $parentPath Can I get to the rootPath in one line of code? 回答1: Version for a directory get-item is your friendly helping hand here. (get-item $scriptPath ).parent.parent If you Want the string only (get-item $scriptPath ).parent.parent