calling shell command from peoplecode - shell

I am getting error when calling OS command for Peoplecode using EXEC function.
The call is like this
CommitWork();
&ShellCommand = "/path/mytest.sh param1 param2";
&ReturnCode = Exec(&ShellCommand, %Exec_Synchronous + %FilePath_Absolute);
The &ShellCommand is built using the path, executable and parameters
to be passed as shown above. That command works fine when executed
independently.
I keep getting error 255. Is there anything about the syntax? Does anybody have a tested or working example or any suggestion?

Thank you guys for responding. The command was running fine from shell scripts but not from Peoplesoft. It turned out that the current folder on the application server was not correct. So I added a CD command as the first line in the shell script to change current folder to the correct folder. That worked.
Thanks again.

the syntax looks correct.
I use similar code to call bat files.
Exec("C:\windows\system32\cmd.exe /c C:\Test\mybat.bat param1 param2", %Exec_Synchronous+%FilePath_Absolute);
Have you tried with an absolute path instead of a relative path?

error code 255 seems to be an out of range error code.
see http://tldp.org/LDP/abs/html/exitcodes.html
I would check the assumptions that you're making.
Is the same username running the shell script, your username vs the app server username?
Is the environment set up the same way for the app server username vs your username?
file permissions

Related

Running python script on CMD which uses a folder to output results

I was using Pycharm as my editor to run the scripts since i need to add a task scheduler i had to test the code on the command prompt. Firstly this is the structure of my project.
When i try to run the following line
C:\Users\My_name\AppData\Local\Programs\Python\Python36-32\python.exe "C:\Users\My_name\PycharmProjects\FYP_CB006302\generateSummary.py"
I get this error,
From the knowledge i have i think it is because it doesn't recognize the path.
But when i change the directory to my project folder then give the path to python.exe and type generateSummary.py it works which was done as shown here.
However i highly doubt that this method can be used to task a schedule in Windows. Therefore, any ideas that would to run as shown in the beginning will be helpful.
The problem here is that when you use that line to run a particular script the folder which is causing the error is out of scope.
C:\Users\My_name\AppData\Local\Programs\Python\Python36-32\python.exe "C:\Users\My_name\PycharmProjects\FYP_CB006302\generateSummary.py"
In this case pickle_saves folder is out of scope. You can avoid this by giving a absolute path to that file in line 173. Where the absolute path is something like C:\user\documents\projects\pickle_saves\all_words

Pass arguments in ruby file for meterpreter?

I have this .rb file with the command:
cd /users/someusername/documents
The problem is that instead of "someusername", i would like to get the actual username of my target pc(which is my own pc used for penetration testing).
Update:
Just to clarify: I am running the resource script using the :resource: command from my meterpreter session. I guess this is different from running meterpreter scripts since the way I am doing it, runs every line in the file as a meterpreter command.
Any idea of how I could get the target's username from the file then? I mean the ENV does not seem to work with this approach. I am open for all suggestions!
Thanks! Much appreciated!
Direct shortcut (if available)
If someusername is the current user name, you could use :
cd ~/documents
Environment variable (if available)
current_user = ENV['USER']
cmd = "cd /users/#{current_user}/documents"
Getting username with id
This command could help you :
current_user = %x(id -un).chomp
cmd = "cd /users/#{current_user}/documents"
Yet another try
According to this post, resource files seem to be ERB files.
So you could write :
cd /users/<%= ENV['USER'] %>/documents
# or
cd /users/<%= %x(id -un).chomp %>/documents

Batch file is working from cmd prompt but not from IIB tool

I have wrapped a simple perl command in a simple windows batch file and executed the same from cmd prompt which worked as expected.
But if I trigger the same batch file from my message flow in IBM Integration Bus, it is unable to recognize the 'perl' command.
Provided the environment variables are set properly and the batch file is working fine from command prompt.
Can anyone please help me on this to identify the issue and resolve the same?
Thanks for the reply.
Actually the error was related to the path from where the batch is calling the perl command.
IIB was always executing it from it's runtime path and that's why it could not recognize the perl command.
The clue is to execute the batch from the path where the perl.exe is present. By following the same the issue got resolved.

Why does one code execute from one folder but not the other?

I was just curious as to why with Windows O/S a simple Ruby file that prints one line to the command prompt can execute correctly from one path, but not the other.
Currently, I have said file in C:\Ruby193\test\lib saved inside the lib folder. When I go to the command prompt and set the path to C:\Ruby193\test\lib, I'd expect to see the code string be printed to the command prompt. However, nothing but an empty line is produced, and if I go up the path and set it to C:\Ruby193\test and execute the ruby file from there, it works just fine.
Does anyone have a sound explanation as to why it works that way? Would this also be the same case for a MAC O/S as well?

c:\Ruby187\bin\ruby.exe: No such file or directory

I have been running my Ruby program using the Git Bash console for a while now.
Lately, when I wanted to run a simple ruby program, i go the following on the console:
c:\Ruby187\bin\ruby.exe: No such file or directory
Why is that? And, how can I solve this issue?
Thanks.
Check the PATH environment variable under both User and System.
Looks like it sees where it should be. Potentially a permissions issue? Can you run with a regular command prompt? Start->run, cmd.exe, ruby -v?
It seems that I had to explicitly save my ruby program with the extension .rb added at the end of the file name for this problem to disappear.
Thanks.

Resources