Invoking shell command within XSLT?

Is it possible to invoke shell commands within XSLT? Something like
<code syntax="python">print(1+2)</code>
and generate
<code>3</code>
or something like that? A newbee here ;-)
Last edited by xanb (2014-07-11 12:27:20)

I don't think xslt itself can call external interpreters.  Xslt can do the calculations and even conditionals, but if you want to use python, or other interpreters, you'd need some sort of "preprocessor" step.
Depending on your actual goals, you may be interested in the various "literate programming" tools.  I don't know of one of the top of my head for having scripting languages embedded in an xml document, but it wouldn't surprise me if there were some.  Most of the ones I know are for embedding various code (C, R) in (La)Tex documents.  I use Sweave daily which is a latex document with R code that the R interpreter processes first to replace with the results, then the latex tools make the final document.
EDIT: This may be of interest.
Last edited by Trilby (2014-07-11 12:35:00)

Similar Messages

  • Passing parameters to shell command within a MAXL script

    Hi all,
    we are trying to run the following from MAXL console
    MAXL> msh script.msh 100 c:\t.txt
    where script.msh has the line:
    shell 'echo $1 >> $2'
    we are looking to add a line with text "100" to the file C:\t.txt but it's actually creating a file called $2 with the text "$1" within it.
    How can we workaround it?
    Thanks

    If I understood well you command line, we would have .log and .err files but .err would be also redirected to .log apart from .err, right?^^^Exactly. That way you can look at either stream, or both. If you think about it, you could test for the existence of any .err file (or come up with your own unique extension for that directory) and flag that after the fact with an email, and attach the specific error and the overall stream. Mind you, given the size of your files, you might want to zip them down first.
    It's the best (or, depending on your outlook, the worst) of all worlds.
    Scripting is one of those things that isn't very sexy, and when it's done well it just fades into the background and doesn't get the credit it deserves. But when it blows up or is kludgy beyond compare it makes everyone's life miserable.
    Regards,
    Cameron Lackpour

  • Executing a shell command within vi using aliases

    The behavior of the ksh ENV environment variable has been changed in Solaris 10 and I assume it is related to the reason why I can no longer use aliases when using the "bang" (!) command execution in vi. For a very simple example, if ll were an alias for ls -lFbo entering this in vi:
       :!llwould produce the expected "ls -l" listing of the current directory in previous Solaris versions. Why does this not work in Solaris 10 and is there an alternate way to accomplish the same thing?

    I don't know exactly but the code written below is working fine try the same with your code .Even with your code instead running the code with
    " ./<filename> ",if you execute it with "sh <filename>" command without changing the mode of the file it is executing properly.
    import java.io.*;
    import java.util.*;
    public class ScriptBuilder
    public ScriptBuilder()
    public void writeScript() throws java.io.IOException
    FileWriter writer = new FileWriter(new File("test_script"));
    writer.write("#! /bin/sh\n");
    writer.write("ll>/home/faiyaz/javaprac/checkll");
    writer.flush();
    writer.close();
    Runtime rt= Runtime.getRuntime();
    rt.exec("chmod 777 test_script");
    rt.exec("./test_script");
    } public static void main (String[] args)throws java.io.IOException
    ScriptBuilder sb = new ScriptBuilder();
    sb.writeScript();
    }

  • Execute shell command from within pascal code

    Hello there,
    I am trying to execute a shell command from within my pascal code. I use XCode together with FreePascal. I have tried something like:
    exec ('program', 'options');
    adding the 'Dos' unit to the Uses clause of my program.
    Thus, e.g.,
    exec ('mkdir', '/A')
    to create a directory with the name 'A'.
    However, my attempts so far were unsuccessful. Can anyone help me on this, and perhaps provide a simple example of how to do it right?
    Thank you in advance,
    Shane

    In the mean time, I found the problem myself. I am just posting the solution here for anyone that is interested. My original solution was correct, in that the 'Dos' Unit must be added, and that the right command is 'exec'. There was however a problem with the correct path to the program that I wanted to invoke. In the shell, this program was accessible from anywhere. However, in the 'exec' command, the full path to the program must be given. Since I am not a Unix expert, I don't know the reason for this.
    So, in summary, the solution is:
    Uses Dos;
    begin
    exec ('full path to program', 'program options');
    e.g.: exec ('/bin/sh', '/run.sh') to process the commands in the file /run.sh
    end
    Hope this may be of help to anyone else.
    Shane
    Mac OS X (10.3.9)
    Mac OS X (10.3.9)
    Mac OS X (10.3.9)

  • 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

  • Shell commands in applescript noob

    Hi all this is my first post in these forums and I come seeking help with a certain script I'm writing for my current college job. The purpose of the script is to install creative cloud from a server and this is as far as I've got. First I can get as far as setting the correct directory in the server by doing:
    do script "cd /Volumes/applications/Mac/'Adobe Creative Cloud'/'Enterprise - enduser'/Build"
    now when I press run the terminal screen pops up just fine with no errors in the right directory. However I've been reading up that to do other commands in the same shell I must do do shell script. When doing this however terminal doesn't do...anything. The reason why I was trying this is because my next command would be initiating the install which is the command:
    "installer -verbose -pkg 'enterprise_Install.pkg' -target /" with adminitrator privilages
    Now my question is how would formulate this within applescript? Thanks.

    do shell script "cd /Volumes/applications/Mac/'Adobe Creative Cloud'/'Enterprise - enduser'/Build ;  installer -verbose -pkg 'enterprise_Install.pkg' -target / with administrator privilages"
    You got the double quote in the wrong place.
    do shell script "cd /Volumes/applications/Mac/'Adobe Creative Cloud'/'Enterprise - enduser'/Build ;  installer -verbose -pkg 'enterprise_Install.pkg' -target / " with administrator privilages
    It is easier to diagnose problems with debug information. I suggest adding log statements to your script to see what is going on.  Here is an example.
        Author: rccharles
        For testing, run in the Script Editor.
          1) Click on the Event Log tab to see the output from the log statement
          2) Click on Run
        For running shell commands see:
        http://developer.apple.com/mac/library/technotes/tn2002/tn2065.html
    on run
        -- Write a message into the event log.
        log "  --- Starting on " & ((current date) as string) & " --- "
        --  debug lines
        set unixDesktopPath to POSIX path of "/System/Library/User Template/"
        log "unixDesktopPath = " & unixDesktopPath
        set quotedUnixDesktopPath to quoted form of unixDesktopPath
        log "quoted form is " & quotedUnixDesktopPath
        try
            set fromUnix to do shell script "sudo ls -l  " & quotedUnixDesktopPath with administrator privileges
            display dialog "ls -l of " & quotedUnixDesktopPath & return & fromUnix
        on error errMsg
            log "ls -l error..." & errMsg
        end try
    end run

  • How to run 'Get-AssignedAccess' or 'Set-AssignedAccess' power shell commands in c# Application

    Hi,
    I have console application using which i am trying to run power shell command  like 'Get-AssignedAccess' or 'Set-AssignedAccess'.
    i am using below code for this it is throwing exception 'Get-AssignedAccess' doesn't exist in cmdlet which is correct because these commands belongs to function category.
    using (PowerShell pwInstance = PowerShell.Create())
                            pwInstance .AddScript("Get-AssignedAccess");
                            var result = pwInstance .Invoke();
    How can we execute this kind of command using c#?
    Thanks,

    Hi prakashlight,
    Thank you for comming back and tell us the result. For more information about how to run PowerShell script in C# language, you can refer to this blogpost here:
    Executing PowerShell scripts from C#
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • PROBLEM in executing a shell command through Runtime.getRuntime().exec()

    Hi all,
    I was trying to execute the following code:
    import java.io.BufferedReader;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.sql.CallableStatement;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.Statement;
    import java.sql.ResultSet;
    * Created on Mar 13, 2007
    * To change the template for this generated file go to
    * Window>Preferences>Java>Code Generation>Code and Comments
    * @author 195092
    * To change the template for this generated type comment go to
    * Window>Preferences>Java>Code Generation>Code and Comments
    public class ClassReportDeleteDaemon {
         ClassReportDeleteDaemon()
         public static void main(String[] args) throws Exception
              Connection conn = null;
              Statement stmt = null;
              ResultSet rs;
              String strQuery = null;
              String strdaysback = null;
              String delstring = null;
              int daysback;
              try
                   System.out.println("REPORT DELETION ::: FINDING DRIVER");               
                   Class.forName("oracle.jdbc.driver.OracleDriver");
              catch(Exception e)
                   System.out.println("REPORT DELETION ::: DRIVER EXCEPTION--" + e.getMessage());
                   System.out.println("REPORT DELETION ::: DRIVER NOT FOUND");
              try
                   String strUrl = "jdbc:Oracle:thin:" + args[0] + "/" + args[1] + "@" + args[2];
                   System.out.println("REPORT DELETION ::: TRYING FOR JDBC CONNECTION");
                   conn = DriverManager.getConnection(strUrl);
                   System.out.println("REPORT DELETION ::: SUCCESSFUL CONNECTION");
                   while(true)
                        System.out.println("WHILE LOOP");
                        stmt = conn.createStatement();
                        strQuery = "SELECT REP_DAYS_OLD FROM T_REPORT_DEL";
                        rs = stmt.executeQuery(strQuery);
                        while(rs.next())
                             strdaysback = rs.getString("REP_DAYS_OLD");
                             //daysback = Integer.parseInt(strdaysback);
                        System.out.print("NO of Days===>" + strdaysback);
                        delstring = "find /tmp/reports1 -name " + "\"" + "*" + "\"" + " -mtime +" + strdaysback + " -print|xargs rm -r";
                        System.out.println("DELETE STRING===>" + delstring);
                        Process proc = Runtime.getRuntime().exec(delstring);
                        //Get error stream to display error messages encountered during execution of command
                        InputStream errStream=proc.getErrorStream();
                        //Get error stream to display output messages encountered during execution of command
                        InputStream inStream = proc.getInputStream();
                        InputStreamReader strReader = new InputStreamReader(errStream);
                        BufferedReader br = new BufferedReader(strReader);
                        String strLine = null;
                        while((strLine=br.readLine())!=null)
                             System.out.println(strLine);
                   }     //end of while loop
              }     //end of try
              catch (Exception e)
                   System.out.println("REPORT DELETION ::: EXCEPTION---" + e.getMessage());
                   conn.close();
         }     //end of main
    }     //end of ClassReportDeleteDaemon
    But it is giving the error "BAD OPTION -print|xargs". The command run well in shell.
    Please help.
    Thanking u.......

    Since the pipe '|' is interpreted by the shell then you need the shell to invoke your command
            String[] command = {"sh","-c","find /tmp/reports1 -name " + "\"" + "*" + "\"" + " -mtime +" + strdaysback + " -print|xargs rm -r"};
            final Process process = Runtime.getRuntime().exec(command);
      You should also read http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html at least twice and implement the recommendation regarding stdout and stderr.
    P.S. Why are you not using Java to find and delete these files?
    Message was edited by:
    sabre150

  • Cisco Secure ACS 4.2 - Group Setup w/Shell Command Authorization Sets

    Hello All,
    I am trying to create a user so that I can provide him only to run commands that I have designated them to run within my "Shell Command Authorization Set". This seems to work great, however I cannot find anywhere I can "hide" commands they do not have access to. For instance, once the user is logged into the switch they can do a show ? and get a list of commands. I would like to know if there is an option to only display commands the user has access to in ACS.
    My Steps:
    Created a user in ACS
    Shared Profile Components
    Create Shell command Autorization Set - "ReadOnly"
    Unmatched Commands - Deny
    Unchecked - Permit Unmatched Arg
    Commands Added
    permit interface
    permit vlan
    permit snmp contact
    permit power inline
    permit version
    permit switch
    permit controllers utilization
    permit env all
    permit snmp location
    permit ip http server status
    permit logging
    Created a group - "GroupTest" with the following
    Confirgured - Network Access Restrictions (NAR)
    Max Sessions - Unlimited
    Enable Options - No Enable Privilege
    TACACS+ Settings
    Shell (exec)
    Priviledge level is check with 1 as the assigned level
    Shell Command Authorization Set
    "ReadOnly" - Assign a Shell Command Authorization Set for any network device
    I have configured following on my Router/Switch
    aaa authorization config-commands
    aaa authorization commands 1 default group tacacs+ if-authenticated
    privilege exec level 1 show log
    I have attached below the documention I have gone over.
    http://www.cisco.com/en/US/products/sw/secursw/ps2086/products_configuration_example09186a00808d9138.shtml
    http://www.cisco.com/en/US/docs/net_mgmt/cisco_secure_access_control_server_for_windows/4.2/user/guide/GrpMgt.html#wp478624

    "you are testing with privilege level 15 or below 15. Because when you are using below 15 level user, first it will check local command authorization set. For example if you want to execute sh runn command with level 5 user, first it will check local command set. If the sh runn command exits in local command set then it will send request to ACS. If it is not in the command set, it won't send request to ACS. That's why you don't see debug. For 15 level users it will directly send request to ACS. Configure command set locally and try it should work.
    Correct me if I am wrong."
    Regards
    Vamsi

  • Execute shell command from Java

    Hi all,
    I need some idea for executing shell script from Java programe.
    For example i have start.sh script in /tmp/start.sh  folder of unix server.
    I want to execute shell script from local java code.
    Any idea on this.

    Hi,
           Read the following articles/posts, maybe this could help you:
          How to execute shell command from Java
    Running system commands in Java applications | java exec example | alvinalexander.com
    Want to invoke a linux shell command from Java - Stack Overflow

  • Executing shell command

    hi
    i waould like to know if any one can tell me how to execute a shell command or call an from within a class file.
    i am required to write a program which creates a servlet file internally everytime it is run.
    i want to know how to execute the shell command in java so that i can compile that file after creating the file from within the class file and not leave it to the user to do it.

    Runtime.getRuntime().exec("<your_command>");

  • Need a power shell command for Front End fail over?

    We have a Lync 2013 infrastructure with 2 front ends and 2 edges. 
    The environment was setup by a partner and the servers were configured for failover in case one goes down in the pool. 
    However the last time windows updates were applied and the primary FE had to be restarted, the secondary FE did not automatically switch over as the active server and it caused a companywide outage. 
    In speaking with the contractor, they said that well no it would not automatically do this, you need to run a Lync PowerShell to have it switch over. 
    My BS radar went off, but I wanted to ask you if this sounds right or is possible. 
    If it must be done, could you give me the power shell command.
    Thanks

    Hi,
    Did you solve the issue with the help of the people above provided?
    If you use a Lync server Enterprise edition, it is recommended to deploy at least three FE servers.
    If you use two Lync server Standard edition for DR,
    when one of the servers fails in the Pool Pair, the administrator need to manually failover the pool to the other member of the Pool Pair using the
    command: Invoke-CsPoolFailover -PoolFQDN <Pool1 FQDN> -DisasterMode -Verbose
    The Automatic failover and failback for
    Voice option and the associated time intervals in Topology Builder apply only to the voice resiliency features that were introduced in Lync Server 2010. Selecting this option does not imply that the pool failover discussed in this document is automatic.
    Pool failover and failback always require an administrator to manually invoke the failover and failback.
    You can refer to the link below about how to failover a pool: 
    http://technet.microsoft.com/en-gb/library/jj204678.aspx
    Best Regards,
    Eason Huang
    Eason Huang
    TechNet Community Support
    Does it help, yes and no.  FYI, we are running Enterprise Edition front ends for our single pool.  The new environment was setup as a proof of concept and we installed the bare minimum # of servers at the time.
    The articles suggested from above pretty much just say if one of your FE's goes down, bring it back up as soon as possible.  Both of our FE's need windows updates applied ASAP and it could an hour or more (likely).  Here is a quote from the article:
    If for some reason you need to bring both servers down at the same time, do the following when the downtime for the pool is finished:
    The best practice is to restart both Front End Servers at the same time.
    If the two servers cannot be restarted at the same time, you should bring them back up in the reverse order of the order they went down.
    If you cannot bring them back up in that order, then use the following cmdlet before bringing the pool back up:
    Reset-CsPoolRegistrarState -ResetType QuorumLossRecovery -PoolFQDN <FQDN>
    The last time the main FE went down for service, we left the secondary FE on but there was still an outage.  Then brought back the formerly active FE fist and service was restored.  Basically I need to know how to switch the passive to the active
    node before/while the primary is offline.  And if required once both FE's are back up, to switch the service from the secondary that became active, back to the primary server as it was before.  Make sense?  Perhaps I'm still missing something
    after reading the articles.  The powershell commands list just updating the topology after both servers come back online.

  • Executing commands within .bat file sequentially within the same cmd window

    We have a .bat file that contains several commands. Each command invokes an .exe with arguments.
    When I invoke the .bat file programatically using the command "cmd.exe /c myfile.bat", the commands are running parallelly.
    Within the .bat file, I also tried using start "" /wait /b "myprocess.exe" instead of just
    "myprocess.exe", but both gives the same result.
    Any solution to this?
    Note:
    We use Windows 7 environment.

    I am invoking the batch programatically in c#.
    As per your suggestion, I modified the code as below to execute bat file directly instead of using cmd.exe.
    Process proc = new
    Process();
    proc.StartInfo.FileName
    = "c:\\myfile.bat";
    proc.Start();
    But still I could see the parallel execution of commands within the bat file.
    I was not able to use Call command as I have to invoke programatically.
    Is there a way to invoke Call command from c#?

  • Shell Command Authorization Sets for device using NDGs??

    Hello. I NDGs configured, there is a group called "GR1" with 30 switch.
    This group is set up a Shell Command Authorization set called "Monitoring", in which only show commands, ping and traceroute are allowed.
    I want to let users switch in only 10 of the group "GR 1" to configure certain interfaces and IP addresses, switch to the other not. ! Note: The number of interface is not the same for each switch, one can be FA0 / 1, but for others it may fa0/3.etc.
    I want to retain these 10 switch within the group "GR1", it is possible to make this configuration?
    - Thanks

    I've edited my earlier post to make it more clear. You can assign Shell Auth. Sets at the user,group or NDG level.More details are mentioned on the following link:
    http://www.cisco.com/en/US/docs/net_mgmt/cisco_secure_access_control_server_for_windows/4.2/user/guide/SPC.html#wpmkr697610
    AFAIR, one device (AAA Client) can be part of only one NDG, so you cannot achieve your requirement by using per-NDG Shell Command Authorization sets. Unless you break up the NDG into more than one NDG.
    You can assign the authorization set at the user or group level (after putting the appropriate users in the group) to achive your requirement.
    You could also use the 'privilege' command on the switch to make sure that users can see only the commands you want. E.g. when a user logs in he will be placed at level 7. Now you can keep the undesired commands at level 15 and bring down the desired commands at level 7. All other users would be assigned a lower level (e.g level 5), so they wont be able to run these commands.
    Regards
    Farrukh

  • ACS 5.x using of per-user Shell Command Authorisation with NDGs

    We have an implemented of ACS 4.x which allows customers access to their own devices (defined in distinct NDGs). The NDGs are referenced in the "Shell Command Authorization Set" component of "TACACS+ Settings" under the "Assign a Shell Command Authorization Set on a per Network Device Group Basis". How would this map onto ACS 5.x rule-based functionality; would an authorization rule be require for each user?
    Thanks,
    Matt

    Hi Matt
    In ACS 5 you would create an authorization rule for each user or identity group. You could then add conditions to each policy to allow them access to specific devices. You would then add an authorization rule to each policy with your specific shell commands added to it.
    If your authorization policies are a mixture of internal users and AD users then you would need to use a identity store sequence for each policy, rather than specifically choosing internal user or AD user. This is something I found out recently.
    So the process would be
    create an access service for tacacs
    then create a service selection policy to match the tacacs protocol and maybe a specific device type such as cisco router.
    then configure your identity within the access service
    then configure your authorization policies within the access service
    I'm no expert on the new ACS and I'm not 100% I'm doing it the correct way but I have done lots of testing and things are working as I want them too. I can allocate admin and or read only access to users based on their AD group.
    You need to set up your NDG in a way you can be as granular as possible within your policies.
    Cheers
    Jay

Maybe you are looking for