- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
The X command/statement I use to execute some .bat files does not work anymore, It was working in the past.
This condition applies to cmd commands, like <<X "del c:\test.txt";>> or <<X "c:\test\test_1\sample.bat">>. You can find the details below.
Thanks.
/*
>>>> CODE_BLOCK_1
*/
options noxwait noxsync;
data _null_;
/*1.expression*/
rc1 = system('del D:\BAT_TEST\b.txt');
put rc1=;
/*2.expression*/
rc2 = system('notepad');
put rc2=;
/*3.expression*/
rc3=system("cmd");
put rc3=;
/*4.expression*/
rc4 = system("copy D:\BAT_TEST\a.txt D:\BAT_TEST\b.txt");
put rc4=;
/*5.expression*/
rc5 = system("notepad_2");
put rc5=;
run;
/*
>>>> CODE_BLOCK_1 DOES NOT WORK
>>>> 2. and 3. expression work , they open notepad and cmd applications
>>>> but 1. and 4. expression do not work. And they generate an error code like "-2147475449", but no documentation is available on the web
>>>> I can find just one discussion about it --> https://social.technet.microsoft.com/Forums/de-DE/62fb1152-9604-4f68-a6be-a3f6fa8019a9/returncode-21...
>>>> I have converted "-2147475449" to decimal and result is "80002007", but still there is no evidence about the issue.
>>>> It looks like we can not execute cmd commands from sas, but in normal cmd window same command works fine
>>>> An interesting detail is, the last expression(5. expression) generates the same result as 1. and 4. expression, -2147475449. But only difference between 5. expression
and 2. expression is wrong application definition. I have added an "_2" string to "notepad".
I mean there is no different error code like "notepad_2 application was not found" etc...
>>>> Log details are below
rc1=-2147475449
rc2=0
rc3=0
rc4=-2147475449
rc5=-2147475449
NOTE: DATA statement used (Total process time):
real time 0.12 seconds
user cpu time 0.03 seconds
system cpu time 0.04 seconds
memory 274.96k
OS Memory 29416.00k
Timestamp 12/19/2014 12:45:06 PM
Step Count 116 Switch Count 0
>>>> In the conf. file XCMD option is set like -XCMD
>>>> Log details are below
%put XCMD Value = %sysfunc(getoption(noxcmd));
XCMD Value = XCMD
*/
/*
>>>> CODE_BLOCK_2
*/
x 'del D:\BAT_TEST\b.txt';
/*
>>>> CODE_BLOCK_2 DOES NOT WORK
>>>> Result is same as CODE_BLOCK_1
>>>> Log details are below
1368 x 'del D:\BAT_TEST\b.txt'
1368! ;
*/
/*
>>>> CODE_BLOCK_3
*/
filename test 'D:\BAT_TEST\b.txt';
data _null_;
rc=fdelete('test');
put rc=;
msg=sysmsg();
put msg=;
run;
/*
>>>> CODE_BLOCK_3 WORKS FINE
>>>> It deletes the file(D:\BAT_TEST\b.txt)
>>>> Log details are below
06 filename test 'D:\BAT_TEST\a.txt';
1307 data _null_;
1308 rc=fdelete('test');
1309 put rc=;
1310 msg=sysmsg();
1311 put msg=;
1312 run;
rc=0
msg=
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
user cpu time 0.00 seconds
system cpu time 0.01 seconds
memory 256.00k
OS Memory 29416.00k
Timestamp 12/19/2014 11:12:15 AM
Step Count 104 Switch Count 0
*/
/*
>>>> CODE_BLOCK_4
*/
x notepad;
/*
>>>> CODE_BLOCK_4 WORKS FINE
>>>> It opens notepad.exe
>>>> Log details are below
1385 x notepad
1385! ;
*/
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Several things here. Firstly what is it your trying to do. If its delete files then use the SAS functions there. If your trying to do some more things in your OS, then IO would suggest you look at scripting for the OS, there are far better alternatives out there for example: https://www.autoitscript.com/site/
VB scripting etc. Secondly your have provided a wall of text there but no diagnostics. You are sending commands out to the OS, therefore you need to check that the files/paths are correct and present, run the command in the OS - I note that your command appears to be for windows, ensure the code isn't running on a mainframe. Make sure you have permission to delete from that directory. It not to do with the xcmd if some command work and others not. More likely to be a wrong path/file or permission.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
1-I have permission to delete these files
2-I have already tried to delete the files from CMD, and it works, no problem
3-All the paths are actual, as I told at item-2 everything is ok when I try to delete(or another operation) from CMD
4-There is no situation like "some command work and others not", no command(CMD command) works with X statement or X command, and same commands work with a filename epx. as in "CODE_BLOCK_3", so I just meant "it is not about" XCMD option
5-I can already solve the problem with a filename exp. as in "CODE_BLOCK_3", my curiosity is what causes this problem, so your first suggestion is not applicable for me
6-All of the answers of your questions already exist in my message, that s why I have provided a wall of text.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
What if you try to run the del or copy command with "cmd /c " prepended?
I ask because cmd exists as cmd.exe, but there is no copy.exe or del.exe
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Your suggestion is very helpful and works, but I still curious about the problem, because it was working one month ago.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
It could be a Windows update, or someone changed settings at the server so that the commands that are internal to the shell (like copy and del) don't work under certain circumstances. Or SAS is calling a different shell than the orginal cmd now.
You are working in a Windows environment, so expect the unexpected to happen.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
One of your symptoms look like issue I had in past on Unix where someone had created an alias for the rm command to always add the -i option so that the operating system was expecting user confirmation before removing a file. Is it possible in Windows to set on option that always forces the user to confirm file deletions ?
This is why I always try to wrap OS commands inside of a data step using PIPE so that I can see any messages that the OS might be trying to send me. For example try this for the expression 4.
data _null_;
infile "copy D:\BAT_TEST\a.txt D:\BAT_TEST\b.txt" pipe ;
input;
put _infile_;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
you are right, I am using this method right now to get a quickwin.
But as I told to KurtBremser it is just curiosity
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You also mention "it was working in the past". Have you had any changes to your system such as upgrade of OS, many things from Windows quit working or require substantial changes with the release of Windows 7, SAS version, network settings. Also if SAS is running in a server environment then the SAS Admin may have changed some setting related to the X command.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
It is win2008 R2
I have checked everything about this problem on the OS side, but I could not find any evidence. Of course I dont know where to look, if you have any suggestion I can try...
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Remember there is a difference in the environment you are getting using the X-cmd and what you are doing in a clean users/shell prompt.
Ah you arlready noticed this difference
The approach of Tom using the piping is the most clean why to see the most of the messages and it helps in synchronizing the processing.
That synchronizing of processes is an inforeseen pitfall. As normal user you are expecting to see what is happening .... mythe to be busted.
Many programs are starting a new shell that is popping up, dropping the old one. Notepad is doing that.
The piping is forcing a sync execution of the xcmd, there is however a system option that can change that behavior with x-usage.
See SAS(R) 9.3 Companion for Windows (xsync xwait). When it set to asynchronous mode you will see nothing to be happened where it is actually run.
As you are x function is working you could verfiy the shell-environment. Use the set command! There must be differences the start of sas is changing that environment.
One of those change must be the root-cause of your issue.
The same is even more worse in Linux/Unix when you get the xcmd active you are inheriting a lot of the objectspawners key and not your key. Limits and other special behavior can be surprising.
My advice:
only let OS guys let install SAS when they understand SAS and verify the all this functionality not getting harmed by their standard way of working.