w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Rescuing bash/system STDERR in Ruby
Instead, I'm getting: "Reached point #1" line 1: eho: command not found "Reached point #2" So in other words, it got rescued, but not in the way that you're expecting. What you actually want is probably more like this: ret = system("sh my_shell_script.sh") puts $? unless ret http://www.ruby-doc.org/core-2.0/Kernel.html#method-i-system

Categories : Ruby

Why does the type System.__ComObject claim (sometimes) to be public when it is not?
Mono's implementation of __ComObject may give some clues. It is indeed declared as internal, but the comments say "It has no public methods, its functionality is exposed trough System.Runtime.InteropServices.Marshal". I haven't dug into Marshal, but I would assume it is responsible for the implementation of GetType(), so it could customize IsPublic property too. In my experience, Type.GetType("System.__ComObject").IsPublic is always true. Regarding GetType("System.Net.Mail.MSAdminBase"), I believe it is a COM class exposed via a customized primary interop assembly, where the visibility of a type can be explicitly controlled (although it's just my thinking, no research has been done). [UPDATE] I've got the latest Framework source code and found I was wrong about my assumption that custo

Categories : C#

Problems when I call a bash script from C with system()
If I understood correctly your bash script runs fine up to some point and then something fails. Probably some process shows an error message but you don't read it because you don't inspect stderr. You should modify the script to write stdout and stderr of the failing step into e.g. /tmp/$$.err for debugging.

Categories : C

Linux C++ program launching a bash script via system call always returns -1
As mentioned in comments your problem is ignorig SIGCHLD. Ignoring SIGCHLD can be used to prevent the creation of zombies. So by setting it disposition to default you can break something. Here example: signal (SIGCHLD, SIG_DFL); system ("some_program"); signal (SIGCHLD, SIG_IGN); If some child process (not child in system) terminated between execution first and third line, it will become a zombie. If you want solve this resources leak correctly, you should use another method (double fork or wait) for solving zombies problem. Why am I getting random exit status here? Because waitpid call failed. If you print out return value of waitpid it will be -1. The value of errno most likely will be ECHILD. Setting disposition of SIGCHLD to SIG_IGN causes breaking wait and waitpid. In y

Categories : C++

Ruby 'net/ssh' & using logic in ruby based on bash cmd response
You can use syntax like this test = %x[ bash command ] for example 1.9.3-p448 :001 > command = %x[ echo "Hello world" ] => "Hello world " You can also check the return code of last command by calling $?.exitstatus

Categories : Ruby

Why does the child of an eval call from bash get orphaned once the parent bash script dies?
This is normal and expected. You sent a signal (presumably SIGTERM) to parent-script and it died, but no signal was sent to another-script. It keeps on running. This is different than what happens when the parent-script job is running interactively on a terminal and you type ^C (or ^Z). In that case, a SIGINT signal is automatically sent to the whole foreground process group. Since another-script is un the same process group as parent-script (by default), they both get the signal and they both die. If you want another-script to die automatically when its parent dies in any other context than when it's a job running in a terminal with job control, you have a few options. parent-script can trap the SIGTERM signal. In the signal handler, it kills its child, and then exits itself. This, o

Categories : Linux

Using curl in bash and ruby
It looks like you have an escaping issue: The quotes are not being escaped properly in the Ruby version. Try this: `curl -d "{\"auth_token\":\"secret\",\"current\":"#{count}"}" http://lab:3030/widgets/connections` This is because both Ruby and the shell escape with the backslash, so escaping happens twice. By adding the extra backslash, the Ruby version is escaped to " instead of just " and then shell can escape the quote for you.

Categories : Ruby

Can't get vim-ruby to work correctly on Git Bash
Do you have filetype plugin indent on (especially indent) in your vimrc? Also note that vim own indentation script for ruby may come in your way, be sure the installation path for vim-ruby plugin appears before default path. By the way, what files did you copy and where? You should have ~/vimfiles/indent/ruby.vim with this content after installation.

Categories : Ruby

Return Java system exit value to bash script
You should do like this: Test.java: public class Test{ public static void main (String[] args){ System.exit(2); } } test.sh #!/bin/bash java Test STATUS=$? echo $STATUS

Categories : Java

How to get the wlan number in the linux system using BASH script
if you just want want ifconfig wlan3 up, then you don't need to isolate the 3. you can get wlan3 with just $ iwconfig | grep -o "^wlan[0-9]+" wlan3

Categories : Linux

How do I split up an argument string Bash-style in Ruby?
Ruby has the module Shellwords: require "shellwords" Shellwords.shellsplit('Test "hello world" foo') # => ["Test", "hello world", "foo"] 'Test "hello world" foo'.shellsplit # => ["Test", "hello world", "foo"]

Categories : Ruby

Sorting using custom value system in ruby
Sort has by value: hash = {:Newbie=>0, :Amateur=>1, :Skilled=>2, :Pro=>3} > hash.sort { hash{a} <=> hash{b} } => [[:Newbie, 0], [:Amateur, 1], [:Skilled, 2], [:Pro, 3]] Or use Ruby Hash#sort_by method: hash.sort_by { |k,v| v }

Categories : Ruby On Rails

Undefined Variable : Claim
Like Nunser said, you need to set the variable $Claim in the view, using $this->set('Claim', $claim) in your controller. The Model fetches data from a database. Then passes it on to a Controller where you can access it via $this->MODELNAME->METHOD. Here the data is processed. Eventually the Controller (not the Model) passes it on to the view. So you need to set it in the Controller. Additionally: if you would be following CakePHP conventions (and really, it's all about conventions) you wouldn't need to use loadModel in line 3 and 4. Maybe have a look at CakePHP relations too. Have a look at this: http://book.cakephp.org/2.0/en/getting-started/cakephp-conventions.html for a short MVC explanation in Cake, and this: http://book.cakephp.org/2.0/en/models/associations-linking-models-together.

Categories : Cakephp

How do I make Octopress use the system version of Ruby?
Octopress is using your system ruby, ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0]. You're using RVM, the ruby-2.0.0-p247 is a ruby you've installed. The repository has an .rvmrc file saying it wants ruby-1.9.3-p448. Try installing it, or change what the .rvmrc wants. edit: The error message tells you what to do: ruby-1.9.3-p448 is not installed. To install do: 'rvm install ruby-1.9.3-p448'

Categories : Ruby

Why does Eclipse claim I have an outdated version of the ADT?
If I click "Check for Updates", Eclipse does its thing and happily reports that there are no updates to install and that everything is up to date. The error dialog is correct -- the latest ADT is 22.0.4. I have no idea why Eclipse's upgrade process would fail to see that, though. Push come to shove, you may need to uninstall and reinstall the ADT.

Categories : Android

Claim based authentication in webrequest
Is this what you are trying to do? http://www.cloudidentity.com/blog/2013/01/09/using-the-jwt-handler-for-implementing-poor-man-s-delegation-actas/

Categories : Asp Net Mvc

MySQL interprets system function call as schema function call (Error Code 1305: Function does not exist)
Make sure you are using MySQL 5.6.1 or later. ST_Contains was added in 5.6.1. From the doc you cited: As of MySQL 5.6.1, corresponding versions are available that use precise object shapes. These versions are named with an ST_ prefix. For example, Contains() uses object bounding rectangles, whereas ST_Contains() uses object shapes. Previous versions of MySQL provide a Contains function which uses the MBR of the two geometries, not their exact shape, for the test. This may work for you if you are unable to upgrade MySQL.

Categories : Mysql

call a bash variable which has spaces
grep isn't going to see that you're passing it a shell variable. Shells expand/replace their variables before firing up the requested program. so grep thinks it's being invoked as ... | grep trunk-index FOR in footer | ... and end up searching for the phrase trunk-index in some non-existent files FOR,in, and footer. Try ... | grep '$grepper' | ... instead.

Categories : Bash

How can I call bash from C with a clean environment?
Some ideas: First of all it would be better in most cases to use the pluggable login architecture PAM. This will ensure, that all PAM-enabled applications and services can use the authentification method (ssh for example) and that there is no way to bypass it using regular services. If you really want to replace login i'd suggest to clear the environment by yourselves using unsetenv for each environment variable set (you may use environ to determine the variables already set). After cleaning up the environment you may use a exec-like call to replace your program with a bash, the environment will be unchanged in this context. You may want to add the command line argument -l to start up bash as it would have been invoked by login. Bash is running some init scripts on startup. You may chec

Categories : C

(Mac Terminal) "System" message when trying to install latest ruby with RVM
The current rvm command outputs the name of the currently active installation of Ruby; in this case, it's using your system's pre-installed Ruby (1.8.7). Try this: rvm install 2.0 # (or whatever version you need) rvm use 2.0 --default # this sets the default to the 2.0 install

Categories : Ruby

ruby system command check exit code
system returns false if the command has an non-zero exit code, or nil if there is no command. Therefore system( "foo" ) or exit or system( "foo" ) or raise "Something went wrong with foo" should work, and are reasonably concise.

Categories : Ruby

Ruby Sinatra templating system with jQuery syntax
It sounds like you are mixing a couple concepts. Nokogiri is used to do CSS and XPath searches through HTML and XML files and lets you iterate though repeating structures, but it does have anything to do with templates. The CSS aspect of Nokogiri uses a jQuery compatible CSS selector, making it easy to piggyback on any HTML/jQuery/CSS knowledge you have. For templates I'd recommend ERB, or Erubis, if you want something similar to what comes with Rails, or HAML, which is my favorite. Templates let you easily emit HTML with your code variables. The syntax was somewhat as follows: something('h1.myTitle').html 'My custom title' (it was very very much like jQuery require 'nokogiri' doc = Nokogiri::HTML('<html><body><h1 class="myTitle">My custom title</h1>&l

Categories : Ruby

Upgrading to Ruby 2.0.0 resulted in "Rails is not currently installed on this system"
Gemsets in RVM are isolated in that they are only available to a single version of Ruby. As such, you need to re-install the Rails gem after installing a new version of Ruby. When a version of Ruby is installed via RVM, 2 associated gemsets will be created simultaneously. One is called "global" and one is called "default". Ruby versions (and their single associated global gemset) are made active via the rvm use ruby_version_here command. The default or (potentially multiple) user generated gemsets are made active via the rvm use gemset_name_here command. Whether a gemset is a global, default, or user generated - it is only available to a single version of Ruby. Here's a nice blog post covering the topic in a bit more detail.

Categories : Ruby On Rails

How to reversibly escape a URL in Ruby so that it can be saved to the file system
One of the ways is by "hashing" the filename. For example, the URL for this question is: http://stackoverflow.com/questions/18234870/how-to-reversibly-escape-a-url-in-ruby-so-that-it-can-be-saved-to-the-file-syste. You could use the Ruby standard library's digest/md5 library to hash the name. Simple and elegant. require "digest/md5" foldername = "http://stackoverflow.com/questions/18234870/how-to-reversibly-escape-a-url-in-ruby-so-that-it-can-be-saved-to-the-file-syste" hashed_name = Digest::MD5.hexdigest(foldername) # => "5045cccd83a8d4d5c4fc01f7b4d8c502" The corollary for this scheme would be that MD5 hashing is used to validate the authenticity/completeness of downloads since for all practical purposes, the MD5 digest of the string always returns the same hex-string. However, I

Categories : Ruby

How correct call make in bash script?
exec is "Instead of the rest of the script, execute this command". Remove them both: # ...as before... cmake ../ make

Categories : Bash

ADFS 2.0 - using claim rules to find out when password expires
You can only access AD attributes that pertain to the logged-in user. For this kind of thing, I would suggest writing a custom attribute store which returns the info. you require.

Categories : Misc

Is a claim on email address good enough for permissions with OAuth
I think you are talking about OpenID but not OAuth. If you look at the main providers, its is okay to assume that they have the valid email attribute of their users (for example, in myopenid.com its optional, however they recommend it, therefor they have the email of most of their users). Email is a unique identifier and it is a good way to identify a user. I do not see any security issue of using email as the identifier at your application. However, will all the users like to share their email attribute with your application is a concern.

Categories : Security

Passing arguments from a call to a bash script to an Rscript
You can have bash pass all the arguments to the R script using something like this for a bash script: #!/bin/bash Rscript /path/to/R/script --args "$*" exit 0 You can then choose how many of the arguments from $* need to be discarded inside of R.

Categories : R

Java call bash "su -c ... username" exit code 125
Problem is that you are trying to execute this: su -c "rsync -avrco --progress /opt/tmp /opt/tmp2" apache using double quotes to delimit one parameter for su, but double quotes are understood by the shell, not by Java (that's why in your second case it works). To make it work try this: import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.InputStreamReader; public class Test { public static void main(String[] args) throws Exception { String[] cmd = new String[] {"su", "-c", "rsync -avrco --progress /opt/tmp /opt/tmp2", "apache"}; Process p = Runtime.getRuntime().exec(cmd); BufferedInputStream inputStream = new BufferedInputStream(p.getInputStream()); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStr

Categories : Java

Generate all possible combinations of a function call using Bash script
Maybe there is a shorter version. I add pure bash soltution: #!/bin/bash # extract arguments to $arg fnc=" - abc(i,j,k)" pre=${fnc%%(*} post=${fnc##*)} arg=${fnc#*(} arg=${arg%)*} # put arguments to arr array IFS=, read -a arr <<<"$arg" num=${#arr[@]} # Generate all output lines for((i=0; i<1<<num; ++i));{ tmp=() for ((j=0; j<num; ++j));{ if ((i & (1<<j))); then tmp[j]="" else tmp[j]=${arr[j]} fi } printf -v tmp ,%s "${tmp[@]}" echo "$pre("${tmp:1}")$post" } Output: - abc(i,j,k) - abc(,j,k) - abc(i,,k) - abc(,,k) - abc(i,j,) - abc(,j,) - abc(i,,) - abc(,,) The script uses variable fnc as input. The it separated to three parts: pre, args, post. The args are arrayized. Then it produces the output for each possible variatio

Categories : Bash

Changing Ruby versions with rbenv from system and "shell" command does not work
Oops! Looks like somebody stuttered. $ ls $HOME/.rbenv/libexec/*shell* /home/tim/.rbenv/libexec/rbenv-sh-shell Looks like there is no shell command, but rather a sh-shell command $ rbenv sh-shell rbenv: no shell-specific version configured Yup. Let's see, if we link to it with a rbenv-shell $ cd $HOME/.rbenv/libexec/ $ ln -s rbenv-sh-shell rbenv-shell then we should get a working shell command $ rbenv shell rbenv: no shell-specific version configured

Categories : Ruby

Configure Claim based identity for multiple applications in localhost
You would need to enable claims authentication in applicationB for this to work. In other words, you would need to setup the same system.identityModel web.config settings in applicationB as in applicationA (as you've shown in your example). Is there a reason that the JavaScript needs to be secured? If the scripts aren't secured, why not just make them accessible to everyone so you won't need to worry about the single sign-on across sites?

Categories : Asp Net Mvc

How to call a bash script automatically when directory contents chage
Linux provides a nice mechanism for that purpose which is called inotify. inotify is mostly available as a C API. But there have been developed shell utilities as well. You should use inotifywait from inotifytools (pkg name in debian) for this. Here comes a basic example: #!/bin/bash directory="/tmp" # or whatever you are interested in inotifywait -m -e create "$directory" | while read folder eventlist eventfile do echo "the following events happened in folder $folder:" echo "$eventlist $eventfile" done Update: If the problem goes complicated, for example you'll have to monitor recursive, dynamic directory structures, you should have a look at incron It's a cron like daemon which executes scripts on certain events. But the events are file system events rather than timer eve

Categories : Linux

How to use system call in php 5.4 (safe_mode=off)
For all information please check the PHP.net site: http://php.net/manual/en/function.exec.php the functions exec(), system(), etc are still there and function the same way as PHP 5.3 with safe_mode = off. The one thing you need to be concerned with is escaping user data like this: <?php exec('mv ' . escapeshellcmd($_GET['originial_file']) . ' ' . escapeshellcmd($_GET['new_file']));

Categories : PHP

Writing a new system call
You should use SYSCALL_DEFINE* to define syscall (I think, this step you did wrong), then add your syscall into sys_call_table, which is architecture-dependent (arch/arm/kernel/calls.S for arm)

Categories : C

Code without system call?
Yes the above has system calls. You can use ptrace() to stop every time there is a system call, and you'll see that there are system calls. How else would the program be loaded and unloaded from memory without the operating system?

Categories : C

understanding system call dup()?
The dup call does not alter the inode or any system table. It only alters the file descriptor table which is a process related table. I think these 2 questions might help you understand what dup actually does. Difference between creating a duplicate file descriptor using dup() and creating a hard link? dup2 / dup - why would I need to duplicate a file descriptor ? Bottom-line : Dup doesn't affect the system in anyway , just the process.

Categories : Misc

When wait system call is used
In many languages, calling a sub process will call wait() for you. For example, in ruby or perl, you often shell out like this: #!/usr/bin/ruby system("ls /tmp") `ls /tmp` This is doing a bunch of magic for you, including calling wait(). In fact, Ruby must wait for the process to exit anyway to collect the output before the program can continue. You can easily create zombies like this: #!/usr/bin/ruby if fork sleep 1000 # Parent ignoring the child else exec "ls /tmp" # short-lived child end When we manually fork/exec, there is no magic calling wait() for us, and a zombie will be created. But when the parent exits, the zombie child will get re-parented to init, which will always call wait() to clean up zombies.

Categories : Linux

Raw Clone system call
I can't say I recommend going with clone if you can use pthreads. I've had bad experience with functions such as malloc() in relation to clone. Have you looked at the man page for documentation? Here is an example that runs for me. I didn't really examine your code to see why it might be crashing. #define _GNU_SOURCE #include <stdio.h> #include <sched.h> #include <sys/types.h> #include <sys/wait.h> #include <linux/sched.h> #include <stdlib.h> #include <unistd.h> #include <assert.h> // Allow us to round to page size #define ROUND_UP_TO_MULTIPLE(a,b) ( ( (a) % (b) == 0) ? (a) : ( (a) + ( (b) - ( (a) % (b) ) ) ) ) struct argsy { int threadnum; }; int fun(void * args) { struct argsy * arguments = (struct argsy *) args; fprintf

Categories : C

using ImageMagick with C++ system call
I guess it’s more about string concatenation? using namespace std; int _tmain(int argc, _TCHAR* argv[]) { if (argc > 1) { string filename = CW2AEX<>(argv[1]); stringstream ss; ss << "display " << filename << "-display :0"; system(ss.str().c_str()); } }

Categories : C++



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.