How to execute a ruby command stored in a variable in powershell
I am executing a command of the form rake
drive:unit_tests:load_data parameters here'. I get the erroris not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.`
I used the code in my ps1 file
$dat1 = one ruby command | Out-String
# $dat1 will contain the value - rake drive:unit_tests:load_data
$dat2 = " parameters here"
$dat3 = $dat1 + $dat2
& $dat3
Hiho,
try running this from the directory you installed Ruby into (or set the location to that directory before that step).
Cheers,
Fred
There's no place like 127.0.0.1
Thanks. I'll try that link now. But, I 'd like to know why the command works when I copy paste / type it, but not when I store it in a variable and then execute it.
When you copy/paste or type it into the console command line, the parser is interpreting it in
Command Parsing Mode.
When you read it back from a variable, the parser is interpreting it in
Expression Parsing Mode.
This article by Keith Hill explains more about the differences:
http://rkeithhill.wordpress.com/2007/11/24/effective-powershell-item-10-understanding-powershell-parsing-modes/
[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Similar Messages
-
How to execute Operating System commands from Stored procedure.
Any help on how to execute Operating System commands from stored procedures will be appreciated.
Nanditha.Search the forums for 'External Procedure' and you will find example code that has been posted before.
-
How to execute a system command with call executable in teststand 4.2.1?
Hi All,
how to execute a system command with "call executable" step in teststand 4.2.1?
example as i want to quit a application.using "taskkill /f /im xxx.exe".And execute other system command(DOS).
BR
JohnnyHi,
I want to run netstat -an | find "8080" command from command prompt using call executable in test stand. after that i would like take the std output to local variable.
Attachments:
callsettings.jpg 404 KB -
How to execute dir dos command in Runtime Execution
Hi All,
Does anybody know how to execute the dir command in DOS in the runtime execution
for example,
when we open the command prompt,
c:\Documents and Settings\java> e:
e:\cd java
e:\dir *.*
how we can list the directory in runtime execution?Process childProcess = Runtime.getRuntime().exec("cmd /C dir *.*");or try with
ProcessBuilder pb = new ProcessBuilder("cmd /C dir *.*");
Process childProcess = pb.start();
NOTE: We can use the ProcessBuilder class from J2SE 5.0+.
for further reference check the below link
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html?page=3
and don't forget to go through API documentation for java.lang package
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/package-summary.html
and if you want to implement it through Java which provides you a list of Files & directories in the present directory here is an example of such code snippet REF:as insisted by my fellow poster.
File file = new File("<present_directory_path>");
if(file.isDirectory()){
String fileNames[] = file.list();
for(String fileName:fileNames)
System.out.println(fileName);
fileNames = null;
or for detailed info use
File files[] = file.listFiles();
for(File fileEntity:files)
System.out.println("FILENAME:"+fileEntity.getName+",IS FOLDER:"+fileEntity.isFolder()+",ABSOLUTE PATH:"+fileEntity.toString()+"FILE SIZE:"+fileEntity.length());
files = null;
}and please do not forget to go through File API Documentation provided as recommended by my fellow poster.
hope this might help :)
REGARDS,
RaHuL -
How to execute a Unix Command in java
Hi, Iam trying to execute a unix command on Sun Solaris by passing that command to a java program. How can I achieve this?
Thanks in advance.Have a look at the javadoc around the Runtime.exec() method. If the command is a shell command then you might have to execute a shell as well as the command.
For example, if you wanted to run a unix command 'ls -l > output.txt' the you might have to pass the following string into the exec() method,
"/bin/sh ls -l > output.txt' -
How to execute a shell command in java?
here, my environment is redhat 7, jdk 1.5.
i don't know how to use the shell command in java.
i want to use this function:
#include <stdlib.h>
int system(const char * string);
please give me some ideas. and Thank you so much if coming with a little demo.i know i should use JNI. because i have to use C lib.
but i have already use JNI to wrapper the original code the cpp code and java code is :
//: appendixb:UseObjImpl.cpp
//# Tested with VC++ & BC++. Include path must
//# be adjusted to find the JNI headers. See
//# the makefile for this chapter (in the
//# downloadable source code) for an example.
#include <jni.h>
#include <stdlib.h>
extern "C" JNIEXPORT void JNICALL
Java_UseObjects_changeObject(
JNIEnv* env, jobject, jobject obj) {
jclass cls = env->GetObjectClass(obj);
jfieldID fid = env->GetFieldID(
cls, "aValue", "I");
jmethodID mid = env->GetMethodID(
cls, "divByTwo", "()V");
int value = env->GetIntField(obj, fid);
printf("Native: %d\n", value);
env->SetIntField(obj, fid, 6);
env->CallVoidMethod(obj, mid);
value = env->GetIntField(obj, fid);
system("preprocess -path sha.c");
printf("Native: %d\n", value);
} ///:~
//: appendixb:UseObjects.java
// From 'Thinking in Java, 2nd ed.' by Bruce Eckel
// www.BruceEckel.com. See copyright notice in CopyRight.txt.
class MyJavaClass {
public int aValue;
public void divByTwo() { aValue /= 2; }
public class UseObjects {
private native void
changeObject(MyJavaClass obj);
static {
// System.loadLibrary("UseObjImpl");
// Linux hack, if you can't get your library
// path set in your environment:
System.load(
"/root/jproj/UseObjImpl.so");
public static void main(String[] args) {
UseObjects app = new UseObjects();
MyJavaClass anObj = new MyJavaClass();
anObj.aValue = 2;
app.changeObject(anObj);
System.out.println("Java: " + anObj.aValue);
} ///:~
i modify this two file which is from TIJ-2edition.
the output is
Native: 2
Native: 3
Java: 3
but what i want to be executed "preprocess -path sha.c" does not work.
i have change the command to, such as "df", "ls" etc. but none of them works
please help me. -
How to execute .sql file in Stored Procedure?
Hi,
I have an urgent requirement, where i have to execute .sql file form Stored Procedure.
This .sql file will have set of update statement. I need to pass value to this update statement.
Kindly please help me.
Regards,
IrfanThis is required as part of Data Migration where i have to do 100 of table's update. Each time update table will defer, so its better to have in separate script file (.sql). Can u paste some sample/syntax to exceute .sql file from stored procedure. I am new to this PL/SQL.
How have you determined that it's "better" to have seperate scripts? I assume you mean the table name will "differ" (and not "defer" - I assume that's just because English isn't your first language? no problem - I think I understand what you're asking).
So what I think you're asking is that you have dynamic table names but each table needs to be updated in the same way?
Question: Why do you have tables with different names that all need the same process doing to them?
Assuming it's a valid requirement (and 99% of the time doing dynamic coding implies it's not).... you could use dynamic code, rather than 'scripts'...
e.g.
create procedure update_table(tbl_name varchar2) is
begin
execute immediate 'update '||tbl_name||' set lastupdate = null';
end;
As you haven't bothered to provide a database version, any example code/data or explanation of what you're actually doing, you're not going to get any detailed answer. Please do take the time to read the FAQ and post appropriate details so people can help you. -
How to execute a shell command?
What class and method should I use to set an environment variable on a local system? And how do I execute a shell command in Java?
Thanks!I don't know about setting environment variables from java, but I do know how to execute system commands (and from there you could modify environment variables).
Use Runtime.getRuntime().exec()
There are quite a few pitfalls with using this though...
1. It's platform dependent
2. Doing this creates a Process. If this process has output, you need to read this, otherwise the output buffer will overflow, and that would be bad... Input is not so bad (either supplying it or not ;)
3. If you use Win for example, and want to do a "dir", there are complications, as there is no dir.exe file, and hence it can't be executed... Do a search for this topic, there's plenty on how to get around it.
Anyway, there's plenty more info on Runtime.getRuntime().exec(), have a look around.
Cheers,
Radish21 -
How to execute any cmd command from java application?
Hi all,
How to execute or call any command of cmd from java application??
Is there any method to do so??
Or, is it possible to do it using Runtime.exec() ??? And if so, how to use it, please explain with ab example...
I'll highly appreciate....
Thank you.If google would be the best option, then I would not be on Sun's forums and I would not have asked experts like you, sir !! :-)
Neway, I got the solution from PhHein !!
Good link indeed..
Cheers.. -
How to Execute Power Shell Command From Windows Application.
Hi All Experts,
I want to execute power shell commands from my windows application.
Is it possible ?
Please let me know your comments..
Thanks.I have not tried this, but apprently it is easy as in the sample pasted below. please see this article for more details
http://geekswithblogs.net/Norgean/archive/2012/09/19/running-powershell-from-within-sharepoint.aspx.
Let me know how it goes...
public string RunPowershell(string powershellText, SPWeb web, string param1, string param2) {
// Powershell ~= RunspaceFactory - i.e. Create a powershell context
var runspace = RunspaceFactory.CreateRunspace();
var resultString = new StringBuilder();
try
// load the SharePoint snapin - Note: you cannot do this in the script itself (i.e. add-pssnapin etc does not work)
PSSnapInException snapInError;
runspace.RunspaceConfiguration.AddPSSnapIn("Microsoft.SharePoint.PowerShell", out snapInError);
runspace.Open();
// set a web variable.
runspace.SessionStateProxy.SetVariable("webContext", web);
// and some user defined parameters
runspace.SessionStateProxy.SetVariable("param1", param1);
runspace.SessionStateProxy.SetVariable("param2", param2);
var pipeline = runspace.CreatePipeline();
pipeline.Commands.AddScript(powershellText);
// add a "return" variable
pipeline.Commands.Add("Out-String");
// execute!
var results = pipeline.Invoke();
// convert the script result into a single string
foreach (PSObject obj in results)
resultString.AppendLine(obj.ToString());
finally
// close the runspace
runspace.Close();
// consider logging the result. Or something.
return resultString.ToString();
Ok. We've written some code. Let us test it.
var runner = new PowershellRunner();
runner.RunPowershellScript(@"
$web = Get-SPWeb 'http://server/web' # or $webContext
$web.Title = $param1
$web.Update()
$web.Dispose()
", null, "New title", "not used");
-Sangeetha -
How to execute Linux OS command from ODI
We have installed Oracle data integrator on windows machine and want to execute linux OS command in a procedure or scenario from ODI .
How could i do that ?
I can see os command elements but they do not work, only windows commands work.There should be linux technology i thinkObviously you can execute Unix OS commands only on Unix OS. Why do you expect Windows to understand it?
The solution in your case would be executing your ODI scenarios with an Agent installed on Unix machine.
Cheers -
How to execute XML batch commands using SharePoint Web services or Client Object Model
Hi,
I have a requirement to execute some batch commands to update SharePoint View Style, how can i do it using SharePoint webservices or SharePoint Client Object model.
I need to execute the following Batch command over a particular web.
<Method ID="UpdateView">
<SetVar Name="Cmd">UpdateView</SetVar>
<SetList Scope="Request">{GUID of List}</SetList>
<SetVar Name="View">{GUID of View}</SetVar>
<SetVar Name="ViewStyle">6</SetVar>
<SetVar Name="RowLimit">100</SetVar>
<SetVar Name="Paged">TRUE</SetVar>
</Method>Hi
I tried it already... But UpdateView Method in the Views.asmx and Lists.asmx, both are not supporting for updating the style of the view (like Boxed, Newsletter...).
If you have any code sample which will do this job with any of the SharePoint web services, please share it.. -
How to execute a cvs command using System Call?
hi all,
how to execute a cvs login command using system call ?
thanks,
damTo anyone that reached this post and still dont have a hint, try this small sample - it logs on CVS using installed CVSNT and execute a fake update:
package testeCVS;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
public class execCMD
String password="yourPassword";
String directory="C:\\CVS\\yourPathToProject";
//send commands to CVS and shows the resulting screen
public int sendCMD(String[] command) throws IOException, InterruptedException
ProcessBuilder pb = new ProcessBuilder(command);
pb.directory(new File(directory));
pb.redirectErrorStream(true); // merge stdout and stderr
Process p = pb.start();
InputStreamReader isr = new InputStreamReader(p.getInputStream());
BufferedReader br = new BufferedReader(isr);
String lineRead;
StringBuilder buffer=new StringBuilder();
System.out.println("Return of shell:");
while ((lineRead = br.readLine()) != null)
buffer.append(lineRead + "\n");
System.out.println(buffer.toString());
return p.waitFor();
//send commands to CVS, send the password after the prompt and show the resulting screen
public int sendDialogCMD(String[] command) throws IOException, InterruptedException
ProcessBuilder pb = new ProcessBuilder(command);
pb.directory(new File(directory));
pb.redirectErrorStream(true); // merge stdout and stderr
Process p = pb.start();
PrintWriter writer = new PrintWriter( new OutputStreamWriter( p.getOutputStream() ));
writer.println( password );
writer.flush();
InputStreamReader isr = new InputStreamReader(p.getInputStream());
BufferedReader br = new BufferedReader(isr);
String lineRead;
StringBuilder buffer=new StringBuilder();
System.out.println("Return of shell:");
while ((lineRead = br.readLine()) != null)
buffer.append(lineRead + "\n");
System.out.println(buffer.toString());
return p.waitFor();
public static void main(String a[]) throws IOException, InterruptedException
execCMD e=new execCMD();
String[] command = new String[5];
command[0] = "cvs";
command[1] = "-q";
command[2] = "-d";
command[3] = ":pserver:yourUserID@localhost:2402/path/of/yourProject"; //in this case using CVS port 2402
command[4] = "login";
System.out.println("exit value=" + e.sendDialogCMD(command));
command = new String[8];
command[0] = "cvs";
command[1] = "-q";
command[2] = "-d";
command[3] = ":pserver:yourUserID@localhost:2402/path/of/yourProject";
command[4] = "-n";
command[5] = "-q";
command[6] = "update";
command[7] = "-dA";
System.out.println("exit value=" + e.sendCMD(command));
}It is possible to send the password on the same command, but I had problems when the password had the character '@' because CVSNT took it as the separator between the username and server name. In that case the command is: ":pserver:yourUserID:yourPassword@localhost:2402/path/of/yourProject" -
How to execute a FrameMaker command (ExtendScript)
Hi, does anyone know how to execute a command that your script did not create? In particular, I want to invoke the Edit > Update References command and launch that dialog box.
Thanks,
RussHi Russ, I think you want this:
#target framemaker
var cmd = app.GetNamedCommand ("Update");
Fcodes ([cmd.Fcode]);
If this isn't what you are looking for, let me know. Thanks. -Rick -
How to execute the CONNECT command in sql
Hi ,
I am using DB2 database and I need to execute the sql statement
CONNECT TO Database user username USING password.
Can anyone tell me how to execute this query in java.
I tried this by using executeQuery but it was giving a sexception somtehing as follows
COM.ibm.db2.jdbc.DB2Exception: [IBM][JDBC Driver] CLI0637E QUERY cannot be found.
at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.throwInvalidQueryError(SQLExceptionGenerator.java:577)
at COM.ibm.db2.jdbc.app.DB2Statement.executeQuery(DB2Statement.java:597)
at First.detail(First.java:18)
at First.main(First.java:29)
can anyone of you help me out in solving this problemYou need a connection to use JDBC stuff. When you have a connection, you are already logged in. There is no need for a query to connect.
Maybe you are looking for
-
I am not able to delete a missing file from lvlib. Can anyone help with this? Thanks, Saranya Solved! Go to Solution.
-
How to set up rules for emails to go to junk on iphone 4
i have an iphone4 that i use for work and a coworker sent out over 40,000 emails which has now overloaded my email to where i cannot send or recieve emails can i set up rules for his emails to go straight to junk? and how my email address is linked t
-
Dv7 "no speakers or headphones plugged in" error
i just completed a series of HP updates for my HP envy dv7333cl and no longer is my sound working. i had upgraded from windows8 to 8.1 some months ago...but the sound still worked thereafter. there have been further 8.1 updates that might have come i
-
Artist names are case sensitive. how do i fix this?
Hi, With the ipod touch, my artist names are case sensitive, which leads to multiple entries for the same artist. Is there any way to fix this? It is very annoying. Thanks for your help!
-
Singletone inheritanc​e
Hi! I implemented a framework based on pluggins, in which there is a GeneralPluggin and five child pluggins that adds some funcionality. I realized that these pluggins coorespond to the singleton pattern so I used the Goop tool to create them in this